-
Notifications
You must be signed in to change notification settings - Fork 11
proper subreddits abstraction and subredit whole timespan scan #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fiocfun
wants to merge
1
commit into
4pr0n:master
Choose a base branch
from
fiocfun:custom_subs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,14 +19,20 @@ | |
| 'id integer primary key autoincrement, \n\t' + | ||
| 'username text unique, \n\t' + | ||
| 'sinceid text, \n\t' + | ||
| 'created integer, \n\t' + | ||
| 'created integer, \n\t' + | ||
| 'updated integer, \n\t' + | ||
| 'deleted integer, \n\t' + | ||
| 'blacklist integer, \n\t' + | ||
| 'views integer, \n\t' + | ||
| 'rating integer, \n\t' + | ||
| 'ratings integer \n\t', | ||
|
|
||
| 'subs' : | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you're using spaces instead of tabs. |
||
| '\n\t' + | ||
| 'id integer primary key autoincrement, \n\t' + | ||
| 'sub text unique, \n\t' + | ||
| 'sinceid text \n\t', | ||
|
|
||
| 'posts' : | ||
| '\n\t' + | ||
| 'id text primary key, \n\t' + | ||
|
|
@@ -57,7 +63,7 @@ | |
| 'downs integer, \n\t' + | ||
| 'foreign key(userid) references users(id)\n\t', | ||
|
|
||
| 'albums' : | ||
| 'albums' : | ||
| '\n\t' | ||
| 'id integer primary key, \n\t' + | ||
| 'path text unique, \n\t' + | ||
|
|
@@ -76,7 +82,7 @@ | |
| 'source text, \n\t' + | ||
| 'width integer, \n\t' + | ||
| 'height integer, \n\t' + | ||
| 'size integer, \n\t' + | ||
| 'size integer, \n\t' + | ||
| 'thumb text, \n\t' + | ||
| 'type text, \n\t' + # image/video | ||
| 'albumid integer, \n\t' + | ||
|
|
@@ -85,7 +91,7 @@ | |
| 'views integer, \n\t' + | ||
| 'foreign key(userid) references users(id), \n\t' + | ||
| 'foreign key(albumid) references albums(id)\n\t', | ||
|
|
||
| 'zips' : | ||
| '\n\t' + | ||
| 'zippath text unique, \n\t' + | ||
|
|
@@ -129,21 +135,21 @@ def __init__(self): | |
| # Create table for every schema given. | ||
| for key in SCHEMA: | ||
| self.create_table(key, SCHEMA[key]) | ||
|
|
||
| def debug(self, text): | ||
| tstamp = time.strftime('[%Y-%m-%dT%H:%M:%SZ]', time.gmtime()) | ||
| text = '%s DB: %s' % (tstamp, text) | ||
| self.logger.write('%s\n' % text) | ||
| if self.logger != stderr: | ||
| stderr.write('%s\n' % text) | ||
|
|
||
| def create_table(self, table_name, schema): | ||
| cur = self.conn.cursor() | ||
| query = '''create table if not exists %s (%s)''' % (table_name, schema) | ||
| cur.execute(query) | ||
| self.commit() | ||
| cur.close() | ||
|
|
||
| def commit(self): | ||
| try_again = True | ||
| while try_again: | ||
|
|
@@ -152,7 +158,7 @@ def commit(self): | |
| try_again = False | ||
| except: | ||
| time.sleep(1) | ||
|
|
||
| def insert(self, table, values): | ||
| cur = self.conn.cursor() | ||
| try: | ||
|
|
@@ -168,21 +174,21 @@ def insert(self, table, values): | |
| except sqlite3.IntegrityError: | ||
| cur.close() | ||
| return -1 | ||
|
|
||
| def delete(self, table, where, values=[]): | ||
| cur = self.conn.cursor() | ||
| q = ''' | ||
| delete from %s | ||
| where %s | ||
| ''' % (table, where) | ||
| cur.execute(q, values) | ||
|
|
||
| def get_cursor(self): | ||
| return self.conn.cursor() | ||
|
|
||
| def count(self, table, where='', values=[]): | ||
| return self.select_one('count(*)', table, where, values=values) | ||
|
|
||
| def select(self, what, table, where='', values=[]): | ||
| cur = self.conn.cursor() | ||
| query = ''' | ||
|
|
@@ -211,7 +217,7 @@ def select_one(self, what, table, where='', values=[]): | |
| one = execur.fetchone() | ||
| cur.close() | ||
| return one[0] | ||
|
|
||
| def update(self, table, what, where='', values=[]): | ||
| cur = self.conn.cursor() | ||
| if where != '': | ||
|
|
@@ -257,7 +263,7 @@ def add_user(self, user, new=False): | |
| self.debug('add_user: user "%s" already exists in %susers: %s' % (user, 'new' if new else '', str(e))) | ||
| raise e | ||
| self.commit() | ||
|
|
||
| def remove_user(self, user): | ||
| userid = self.get_user_id(user) | ||
| user = self.select_one('username', 'users', where='id = ?', values=[userid]) | ||
|
|
@@ -325,7 +331,41 @@ def set_last_since_id(self, user, since_id): | |
| ''' % (since_id, user) | ||
| cur.execute(query) | ||
| self.commit() | ||
|
|
||
|
|
||
| def add_sub(self, sub): | ||
| cur = self.conn.cursor() | ||
| cur.execute('insert or ignore into subs(sub) values (?)', [sub]) | ||
| self.commit() | ||
|
|
||
| def remove_sub(self, sub): | ||
| self.delete('subs', 'sub like ?', [sub]) | ||
| self.commit() | ||
|
|
||
| def get_subs_list(self): | ||
| result = [] | ||
| for sub in self.select('sub', 'subs'): | ||
| result.append(sub[0]) | ||
| return result | ||
|
|
||
| def get_sub_last_since_id(self, sub): | ||
| cur = self.conn.cursor() | ||
| results = cur.execute(''' | ||
| select sinceid | ||
| from subs | ||
| where sub like "%s" | ||
| ''' % sub) | ||
| return results.fetchall()[0][0] | ||
|
|
||
| def set_sub_last_since_id(self, sub, since_id): | ||
| cur = self.conn.cursor() | ||
| query = ''' | ||
| update subs | ||
| set sinceid = "%s" | ||
| where sub like "%s" | ||
| ''' % (since_id, sub) | ||
| cur.execute(query) | ||
| self.commit() | ||
|
|
||
| def add_post(self, post, legacy=0): | ||
| userid = self.get_user_id(post.author) | ||
| values = [ ( | ||
|
|
@@ -515,8 +555,8 @@ def add_existing_image(self, user, oldimage, oldpath, subdir='', album_id=-1): | |
| self.debug('add_existing_image: create_thumbnail failed: %s' % str(e)) | ||
| thumbnail = path.join(ImageUtils.get_root(), 'images', 'nothumb.png') | ||
| try: | ||
| self.add_image(newimage, user, url, | ||
| dims[0], dims[1], size, thumbnail, 'image', | ||
| self.add_image(newimage, user, url, | ||
| dims[0], dims[1], size, thumbnail, 'image', | ||
| album_id, post, comment) | ||
| except Exception, e: | ||
| self.debug('add_existing_image: failed: %s' % str(e)) | ||
|
|
@@ -598,7 +638,7 @@ def add_existing_album(self, user, oldalbum, oldpath): | |
| except Exception, e: | ||
| #self.debug('add_existing_image: %s' % str(e)) | ||
| pass | ||
|
|
||
| def get_credentials(self, site): | ||
| if self.count('credentials', 'site = ?', [site]) == 0: | ||
| raise Exception('Credentials for %s not found in database, run "Gonewild.py --help" for more info' % site) | ||
|
|
@@ -628,7 +668,7 @@ def set_credentials(self, site, username, password): | |
| from traceback import format_exc | ||
| self.debug('\n%s' % format_exc()) | ||
| raise e | ||
|
|
||
| def update_user(self, user): | ||
| cur = self.conn.cursor() | ||
| query = ''' | ||
|
|
@@ -671,7 +711,7 @@ def mark_as_deleted(self, user): | |
|
|
||
| def already_friend(self, user): | ||
| return self.count('friends', 'username = ?', [user]) > 0 | ||
|
|
||
| def add_friend(self, user): | ||
| cur = self.conn.cursor() | ||
| cur.execute('insert into friends values (?)', [user]) | ||
|
|
@@ -723,7 +763,7 @@ def set_config(self, key, value): | |
| cur.close() | ||
| except Exception, e: | ||
| self.debug('failed to set config key "%s" to value "%s": %s' % (key, value, str(e))) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| db = DB() | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
DB.pyfile automatically creates tables if they don't already exist.gonewilder/py/DB.py
Lines 133 to 137 in 21cf14e