Skip to content

Commit

Permalink
Update export links
Browse files Browse the repository at this point in the history
  • Loading branch information
yatan committed Nov 18, 2017
1 parent fa8eca4 commit bc6bc62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions export_links_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,29 @@ def get_links(username):
file_links.close()
return links

def check_existed_user(username):
cursor = db.cursor()
cursor.execute('SELECT COUNT(*) FROM links WHERE nickname="' + username + '"')
if cursor.fetchone()[0] == 0:
return False
else:
return True



cursor = db.cursor()
for filename in os.listdir('.'):
# print filenames of dir
if ("links_" in filename):
user = filename.split("links_")[1]
userbo = user.split(".txt")[0]
llistat = get_links(userbo)
#Insert link
for link in llistat:
cursor.execute('''INSERT INTO links(nickname, link) VALUES(?,?)''', ((userbo,link, )) )
print "Adding: " + userbo + " amb link: " + link + " to DB."
if not check_existed_user(userbo):
llistat = get_links(userbo)
#Insert link
for link in llistat:
cursor.execute('''INSERT INTO links(nickname, link) VALUES(?,?)''', ((userbo,link, )) )
print "Adding: " + userbo + " amb link: " + link + " to DB."


db.commit()

Expand Down
Binary file modified web/data/crawler
Binary file not shown.

0 comments on commit bc6bc62

Please sign in to comment.