Skip to content

Commit

Permalink
check_if_exist
Browse files Browse the repository at this point in the history
  • Loading branch information
yatan committed Nov 19, 2017
1 parent ed56e39 commit 78566ee
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions get_images_from_profile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from bs4 import BeautifulSoup
import os
import selenium.webdriver as webdriver
import sqlite3

db = sqlite3.connect('web/data/crawler')

# Check user not exist on DB
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

def get_img_url(url):
direccions = []
Expand All @@ -26,10 +38,11 @@ def get_img_url(url):
if ("users_" in filename):
user = filename.split("users_")[1]
userbo = user.split(".txt")[0]
file_links = open("links_" + userbo + ".txt","w")
links = get_img_url(userbo)
for items in links:
file_links.write(items + "\n")
file_links.close()
if (check_existed_user(userbo) == False):
file_links = open("links_" + userbo + ".txt","w")
links = get_img_url(userbo)
for items in links:
file_links.write(items + "\n")
file_links.close()


0 comments on commit 78566ee

Please sign in to comment.