-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from sziyan/database
v1. 1 release
- Loading branch information
Showing
18 changed files
with
244 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from config import Config | ||
import sqlalchemy as db | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
engine = db.create_engine(Config.SQLALCHEMY_DATABASE_URI) | ||
connection = engine.connect() | ||
Session = sessionmaker() | ||
Session.configure(bind=engine) | ||
session = Session() | ||
|
||
|
||
from app import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy import Column,Integer,String, Float | ||
Base = declarative_base() | ||
|
||
class Games(Base): | ||
__tablename__ = 'games' | ||
id = Column(Integer, primary_key=True) | ||
title = Column(String, nullable=False) | ||
link = Column(String, nullable=False) | ||
count = Column(Integer, nullable=True) | ||
rating = Column(Float, nullable=True) | ||
price = Column(String, nullable=True) | ||
category = Column(String, nullable=True) | ||
developer = Column(String, nullable=True) | ||
iap_range = Column(String, nullable=True) | ||
month = Column(String, nullable=True) | ||
|
||
|
||
class Apps(Base): | ||
__tablename__ = 'apps' | ||
id = Column(Integer, primary_key=True) | ||
title = Column(String, nullable=False) | ||
link = Column(String, nullable=False) | ||
count = Column(Integer, nullable=True) | ||
rating = Column(Float, nullable=True) | ||
price = Column(String, nullable=True) | ||
category = Column(String, nullable=True) | ||
developer = Column(String, nullable=True) | ||
iap_range = Column(String, nullable=True) | ||
month = Column(String, nullable=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
basedir = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
class Config: | ||
client_id = 'reddit client id '#reddit client id | ||
client_secret = 'reddit client secret' #reddit client secret | ||
username = 'reddit username' | ||
password = 'reddit password' | ||
user_agent = 'user_agent' | ||
subreddit = ['google_play'] #subreddit to monitor | ||
max_apps = 15 #max number of apps to list in 1 single comment | ||
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'sqlite:///' + os.path.join(basedir, 'mydb.db') #sqlalchemy URI | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
token = 'token' #telegram bot token | ||
chat_id = 'chat_id' #telegram chat id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from app.models import Base | ||
from app import engine | ||
|
||
print('Database updated') | ||
Base.metadata.create_all(engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env python | ||
from migrate.versioning.shell import main | ||
|
||
if __name__ == '__main__': | ||
main(repository='migration', url='sqlite:///gplay.db', debug='False') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@echo off | ||
echo "Make sure in virtualenv folder." | ||
pause | ||
|
||
echo "Create migration folder" | ||
|
||
migrate create migration "Project" | ||
|
||
set /p db=Enter database filename(with .db): | ||
|
||
echo "Setting up version control." | ||
python migration/manage.py version_control sqlite:///%db% migration | ||
|
||
echo "Setting path." | ||
migrate manage manage.py --repository=migration --url=sqlite:///%db% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This is a database migration repository. | ||
|
||
More information at | ||
http://code.google.com/p/sqlalchemy-migrate/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env python | ||
from migrate.versioning.shell import main | ||
|
||
if __name__ == '__main__': | ||
main(debug='False') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[db_settings] | ||
# Used to identify which repository this database is versioned under. | ||
# You can use the name of your project. | ||
repository_id=Project | ||
|
||
# The name of the database table used to track the schema version. | ||
# This name shouldn't already be used by your project. | ||
# If this is changed once a database is under version control, you'll need to | ||
# change the table name in each database too. | ||
version_table=migrate_version | ||
|
||
# When committing a change script, Migrate will attempt to generate the | ||
# sql for all supported databases; normally, if one of them fails - probably | ||
# because you don't have that database installed - it is ignored and the | ||
# commit continues, perhaps ending successfully. | ||
# Databases in this list MUST compile successfully during a commit, or the | ||
# entire commit will fail. List the databases your application will actually | ||
# be using to ensure your updates to that database work properly. | ||
# This must be a list; example: ['postgres','sqlite'] | ||
required_dbs=[] | ||
|
||
# When creating new change scripts, Migrate will stamp the new script with | ||
# a version number. By default this is latest_version + 1. You can set this | ||
# to 'true' to tell Migrate to use the UTC timestamp instead. | ||
use_timestamp_numbering=False |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
09-Jan-20 12:09:40 PM INFO - Monthly top games posted: https://www.reddit.com/r/sziyan_testing/comments/em4dta/top_10_linkme_games_of_the_month/ | ||
09-Jan-20 12:11:25 PM INFO - Monthly top games posted: https://www.reddit.com/r/sziyan_testing/comments/em4eiv/top_10_linkme_games_of_the_month/ | ||
09-Jan-20 12:12:35 PM INFO - Monthly top games posted: https://www.reddit.com/r/sziyan_testing/comments/em4f1o/top_10_linkme_games_of_the_month/ | ||
09-Jan-20 12:13:15 PM INFO - Monthly top games posted: https://www.reddit.com/r/sziyan_testing/comments/em4fdp/top_10_linkme_games_of_the_month/ | ||
09-Jan-20 02:15:38 PM INFO - Monthly top games posted: https://www.reddit.com/r/sziyan_testing/comments/em5pf6/top_1_linkme_games_of_the_month/ | ||
09-Jan-20 02:20:07 PM INFO - Monthly top games posted: https://www.reddit.com/r/sziyan_testing/comments/em5qvy/top_1_linkme_games_of_the_month/ | ||
09-Jan-20 03:59:27 PM INFO - Monthly top games posted: https://www.reddit.com/r/sziyan_testing/comments/em6ngc/top_5_linkme_games_of_the_month/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
import praw | ||
from config import Config | ||
from app.models import Games,Apps | ||
from app import session | ||
import datetime | ||
|
||
logging.basicConfig(level=logging.INFO, filename='monthly.log', filemode='a', format='%(asctime)s %(levelname)s - %(message)s', datefmt='%d-%b-%y %I:%M:%S %p') | ||
current_month = datetime.datetime.now() | ||
month = current_month.strftime('%b %y') | ||
month_game = session.query(Games).filter_by(month=month) | ||
games = month_game.order_by(Games.count.desc()) | ||
#games = session.query(Games).order_by(Games.count.desc()) | ||
|
||
number_of_games = session.query(Games).count() | ||
msg = "" | ||
top_games = [] | ||
reddit = praw.Reddit(client_id=Config.client_id, client_secret=Config.client_secret, username=Config.username, password=Config.password, user_agent=Config.user_agent) | ||
#android_gaming = reddit.subreddit('AndroidGaming') | ||
subreddit = reddit.subreddit('sziyan_testing') | ||
|
||
if number_of_games > Config.max_monthly: | ||
for i in range(0,Config.max_monthly): | ||
top_games.append(games[i]) | ||
else: | ||
for i in range(0,number_of_games): | ||
top_games.append(games[i]) | ||
|
||
##introduction message | ||
msg += 'Hello /r/AndroidGaming! \n\n' \ | ||
'This is a list of top {} games that was found using linkme. \n\n' \ | ||
'Any feedbacks are greatly appreciated! \n\n\n\n'.format(Config.max_monthly) | ||
|
||
##table header | ||
msg += '| Count | Title | URL | Ratings | Price | Category | Developer | IAP |\n' | ||
msg += '| :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: |\n' # seperate header and body | ||
|
||
for i in top_games: | ||
msg += '| {} | {} | [Google Play]({}) | {} | {} | {} | {} | {} |\n'.format(i.count, i.title, i.link, i.rating, i.price, i.category, i.developer, i.iap_range) | ||
|
||
msg += 'This post is automated at the end of every month.' | ||
|
||
submission = subreddit.submit(title='Top {} linkme games of the month!'.format(Config.max_monthly), send_replies=False, selftext=msg) | ||
logging.info('Monthly top games posted: {}'.format(submission.url)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://sqlalchemy-migrate.readthedocs.io/en/latest/versioning.html#project-setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,5 @@ | ||
# import play_scraper as play | ||
# import praw | ||
# from config import Config | ||
# | ||
# reddit = praw.Reddit(client_id=Config.client_id, client_secret=Config.client_secret, username=Config.username, password=Config.password, user_agent=Config.user_agent) | ||
# subreddit = reddit.subreddit('sziyan_testing') | ||
# | ||
# for comments in subreddit.comments(limit=100): | ||
# print(comments.author.name) | ||
# comments.delete() | ||
# | ||
# print("deleted") | ||
# | ||
# for comments in subreddit.comments(): | ||
# print(comments.author) | ||
|
||
#!/home/sziyan/bots/reddit/gplay/venv/bin python3 | ||
|
||
import logging | ||
import re | ||
import praw | ||
from praw import exceptions | ||
import markdown | ||
import html2text | ||
import play_scraper as play | ||
from config import Config | ||
|
||
logging.basicConfig(level=logging.INFO, filename='output.log', filemode='a', format='%(asctime)s %(levelname)s - %(message)s', datefmt='%d-%b-%y %I:%M:%S %p') | ||
logging.info("Bot started successfully") | ||
|
||
reddit = praw.Reddit(client_id=Config.client_id, client_secret=Config.client_secret, username=Config.username, password=Config.password, user_agent=Config.user_agent) | ||
subreddit = reddit.subreddit("+".join(Config.subreddit)) | ||
logging.info("Watching /r/{} ...".format((",/r/").join(Config.subreddit))) | ||
logging.info("Waiting for comments...") | ||
|
||
|
||
link_me_regex = re.compile("\\blink[\s]*me[\s]*:[\s]*(.*?)(?:\.|;|$)", re.M | re.I) | ||
|
||
def get_clean_comment(text): | ||
text_maker = html2text.HTML2Text() | ||
text_maker.ignore_emphasis = True | ||
text_maker.IGNORE_ANCHORS = True | ||
text_maker.IGNORE_IMAGES = True | ||
htmltext = markdown.markdown(text) | ||
output = text_maker.handle(htmltext) | ||
return output | ||
|
||
def get_no_apps(linkme_requests): | ||
app_count = 0 | ||
for rq in linkme_requests: | ||
for item in rq.split(','): | ||
app_count += 1 | ||
return app_count | ||
|
||
def get_all_app_requests(linkme_requests): | ||
apps_list = [] | ||
for rq in linkme_requests: | ||
for item in rq.split(","): | ||
apps_list.append(item) | ||
return apps_list | ||
|
||
for comments in subreddit.stream.comments(skip_existing=True): | ||
print(comments) | ||
|
||
|
||
|
||
game = 'clash of clans' | ||
result = play.search(game,detailed=True,page=1)[0] | ||
print(result['iap_range']) |