def getInfo(sel,lastwords,command,email): sel.open("http://www.twitter.com/home") time.sleep(5) capturepath = "/var/www/profiles/img/" filename = str(int(time.time())) + ".png" capture = capturepath + filename websource = sel.get_html_source() logging.info("account info") #logging.info(websource) try: m = re.search('<span id="following_count" class="stats_count numeric">(.*?)</span>',websource,re.IGNORECASE) following = m.group(1) logging.info("[ok] user is following: " + str(following)) except: logging.error("[failed] amount of following ") pass try: m = re.search('<span id="follower_count" class="stats_count numeric">(.*?)</span>',websource,re.IGNORECASE) followers = m.group(1) logging.info("[ok] user has " + str(followers) + " followers") except: logging.error("[failed] amount of followers") pass try: m = re.search('<span id="me_tweets"><span id="update_count">(.*?)</span>',websource,re.IGNORECASE) tweets = m.group(1) logging.info("[ok] user has " + str(tweets) + " tweets") # remove the comma tweets = tweets.replace(",","") except: logging.error("[failed] amount of tweets") try: m = re.search('<a href="http://twitter.com/(.*?)" class="url" rel="contact" title="(.*?)"',websource,re.IGNORECASE) realname = m.group(2) username = m.group(1) logging.info("[ok] real name is: " + realname) logging.info("[ok] twitter username is: " + username) picture_url = "http://twitter.com/account/profile_image/" + username + "?hreflang=" logging.info("[ok] picture url is: " + picture_url) sel.open(picture_url) time.sleep(4) websource = sel.get_html_source() #logging.info(websource) try: regex = '<img alt="' + realname + '" src="(.*?)"' m = re.search(regex,websource,re.IGNORECASE) profile_picture = m.group(1) logging.info("[ok] got the profile picture from " + realname) except: try: regex = '<img src="(.*?)" alt="' + realname + '"' m = re.search(regex,websource,re.IGNORECASE) profile_picture = m.group(1) logging.info("[ok] got the profile picture from " + realname) except: profile_picture = "http://s.twimg.com/a/1261519751/images/default_profile_1_normal.png" logging.warning("[failed] profile picture regex failed!!!") pass pass try: logging.info("[ok] url of profile picture is " + profile_picture) urllib.urlretrieve(profile_picture, capture) logging.info("[ok] image moved to " + capture) except: logging.warning("[failed] profile picture download failed!!!") pass try: cropme = "convert %s -resize '200' %s" %(capture,capture) os.system(cropme) print cropme logging.info("[ok] image cropped to 200px width") except: logging.error("[failed] image not cropped") pass # sql query try: #q = "INSERT INTO web20suicide.users(`id`,`username`,`friends`,`picture`,`lastwords`,`command`,`t_create`,`email`,`tweets`) VALUES (NULL,%s,%s,%s,%s,%s,CURRENT_TIMESTAMP,%s,%s)" #cursor.execute(q, (username,followers,filename,lastwords,command,email,tweets,)) sendkillermail(capture,username,friends,lastwords,command) logging.info("[ok] user " + username + " added to mysql") try: q2 = "SELECT id FROM web20suicide.users WHERE command='" + command + "' ORDER BY id DESC LIMIT 1" cursor.execute(q2) user_id = cursor.fetchone() user_id = str(user_id.values()) logging.info("fetching raw ID: " + str(user_id)) user_id = user_id.strip("[]L") logging.info("fetching last row ID: " + str(user_id)) except: logging.warning("[failed] to catch last user id") pass except: logging.warning("[failed] mysql insert failed!!") pass except: logging.error("[failed] username, realname, picture failed") pass return following,followers,tweets,username,email,user_id
def getInfo(sel,lastwords,command,email): sel.open("http://www.facebook.com/profile.php") random_wait = random.randint(2,5) time.sleep(random_wait) capturepath = "/var/www/profiles/img/" filename = str(int(time.time())) + ".png" capture = capturepath + filename # get profile name and friends amount with regex-vodoo websource = sel.get_html_source() random_wait = random.randint(1,3) time.sleep(random_wait) try: m = re.search('<img id="profile_pic".*src="(.*?)\"/>',websource,re.IGNORECASE) profile_picture = m.group(1) logging.info("[ok] got the profile picture from " + username) except: try: m = re.search('<img src="(.*).?\"\salt=.*id="profile_pic">',websource,re.IGNORECASE) profile_picture = m.group(1) logging.info("[ok] got the profile picture from " + username) except: logging.warning("[failed] profile picture regex failed!!!") #logging.error(websource) pass pass try: logging.info("[ok] url of profile picture is " + profile_picture) urllib.urlretrieve(profile_picture, capture) logging.info("[ok] image moved to " + capture) except: logging.warning("[failed] profile picture download failed!!!") pass try: cropme = "convert %s -resize '200' %s" %(capture,capture) os.system(cropme) logging.info("[ok] image cropped to 200px width") except: logging.error("[failed] image not cropped") pass try: m = re.search('<h1 id="profile_name">(.*)</h1>',websource,re.IGNORECASE) username = m.group(1) logging.info("[ok] username logged in as " + username) logging.info("[ok] " + username + " last words are " + lastwords) except: logging.warning("[failed] username regex failed!!!") pass try: m = re.search('<a.*?\">(\d*)\sfriends</a>',websource) #logging.info("websource is: " + websource) friends = m.group(1) logging.info("[ok] " + username + " has " + friends + " friends!") except: logging.warning("[failed] friendsamount regex failed!!!") friends = "n/a" pass # sql query try: #q = "INSERT INTO web20suicide.users(`id`,`username`,`friends`,`picture`,`lastwords`,`command`,`t_create`,`email`) VALUES (NULL,%s,%s,%s,%s,%s,CURRENT_TIMESTAMP,%s)" # cursor.execute(q, (username,friends,filename,lastwords,command,email)) logging.info("[ok] user " + username + " added to mysql") sendkillermail(capture,username,friends,lastwords,command) try: time.sleep(2) q2 = "SELECT id FROM web20suicide.users WHERE command='" + command + "' ORDER BY id DESC LIMIT 1" cursor.execute(q2) user_id = cursor.fetchone() user_id = str(user_id.values()) user_id = user_id.strip("[]L") logging.info("fetching last row ID: " + str(user_id)) except: logging.warning("[failed] to catch last user id") pass except: logging.warning("[failed] mysql insert failed!!") pass return friends,user_id
def getInfo(sel, lastwords, command, email): sel.open("http://www.linkedin.com/home") capturepath = "/var/www/profiles/img/" filename = str(int(time.time())) + ".png" capture = capturepath + filename # get profile name and friends amount with regex-vodoo websource = sel.get_html_source() try: # regex to catch profile image sel.open("http://www.linkedin.com/myprofile?trk=hb_tab_pro") websource2 = sel.get_html_source() m = re.search( '<a href="\/myprofile\?trk=nus_stat_photo&goback=%2Ehom"><img src="(.*?)shrink_40_40\/(.*?)"', websource2, re.IGNORECASE) profile_picture = m.group(1) + m.group(2) logging.info("[ok] got the profile picture " + profile_picture) except: profile_picture = "http://static03.linkedin.com/img/icon/icon_no_photo_80x80.png" logging.warning( "[failed] 2nd profile picture regex failed, using default one!!!") logging.error(websource2) pass try: logging.info("[ok] url of profile picture is " + profile_picture) urllib.urlretrieve(profile_picture, capture) logging.info("[ok] image moved to " + capture) except: logging.warning("[failed] profile picture download failed!!!") pass try: # modifying pciture so it fits on our wall of fame cropme = "convert %s -resize '200' %s" % (capture, capture) os.system(cropme) print cropme logging.info("[ok] image cropped to 200px width") except: logging.error("[failed] image not cropped") pass try: # regex to catch username m = re.search('<span class="given-name">(.*)</span>\n', websource, re.IGNORECASE) g = re.search('<span class="family-name">(.*)</span>\n', websource, re.IGNORECASE) username = m.group(1) + " " + g.group(1) logging.info("[ok] username logged in as " + username) logging.info("[ok] " + username + " last words are " + lastwords) except: logging.warning("[failed] username regex failed!!!") logging.error(websource) try: m = re.search( '<a href="\/myprofile\?trk=hb_pro" title="Edit profile">(.*?)</a>', websource, re.IGNORECASE) username = m.group(1) logging.info("[ok] " + username + " last words are " + lastwords) except: logging.warning("[failed] 2nd username regex failed!!!") pass pass try: sel.open("http://www.linkedin.com/connections?trk=hb_side_connections") websource = sel.get_html_source() time.sleep(2) m = re.search('<strong id="count-showing">(.*?)</strong>', websource, re.IGNORECASE) friends = m.group(1) logging.info("[ok] " + username + " has " + friends + " friends!") except: logging.error(websource) logging.warning("[failed] friendsamount regex failed!!!") friends = "0" pass # sql query try: # q = "INSERT INTO web20suicide.users(`id`,`username`,`friends`,`picture`,`lastwords`,`command`,`t_create`,`email`,) VALUES (NULL,%s,%s,%s,%s,%s,CURRENT_TIMESTAMP,%s)" #cursor.execute(q, (username,friends,filename,lastwords,command,email)) sendkillermail(capture, username, friends, lastwords, command) logging.info("[ok] user " + username + " added to mysql") try: q2 = "SELECT id FROM web20suicide.users WHERE command='" + command + "' ORDER BY id DESC LIMIT 1" cursor.execute(q2) user_id = cursor.fetchone() user_id = str(user_id.values()) user_id = user_id.strip("[]L") logging.info("fetching last row ID: " + str(user_id)) except: logging.warning("[failed] to catch last user id") pass except: logging.warning("[failed] mysql insert failed!!") pass return friends, user_id
def getInfo(sel, lastwords, command, email): sel.open("http://www.twitter.com/home") time.sleep(5) capturepath = "/var/www/profiles/img/" filename = str(int(time.time())) + ".png" capture = capturepath + filename websource = sel.get_html_source() logging.info("account info") #logging.info(websource) try: m = re.search( '<span id="following_count" class="stats_count numeric">(.*?)</span>', websource, re.IGNORECASE) following = m.group(1) logging.info("[ok] user is following: " + str(following)) except: logging.error("[failed] amount of following ") pass try: m = re.search( '<span id="follower_count" class="stats_count numeric">(.*?)</span>', websource, re.IGNORECASE) followers = m.group(1) logging.info("[ok] user has " + str(followers) + " followers") except: logging.error("[failed] amount of followers") pass try: m = re.search( '<span id="me_tweets"><span id="update_count">(.*?)</span>', websource, re.IGNORECASE) tweets = m.group(1) logging.info("[ok] user has " + str(tweets) + " tweets") # remove the comma tweets = tweets.replace(",", "") except: logging.error("[failed] amount of tweets") try: m = re.search( '<a href="http://twitter.com/(.*?)" class="url" rel="contact" title="(.*?)"', websource, re.IGNORECASE) realname = m.group(2) username = m.group(1) logging.info("[ok] real name is: " + realname) logging.info("[ok] twitter username is: " + username) picture_url = "http://twitter.com/account/profile_image/" + username + "?hreflang=" logging.info("[ok] picture url is: " + picture_url) sel.open(picture_url) time.sleep(4) websource = sel.get_html_source() #logging.info(websource) try: regex = '<img alt="' + realname + '" src="(.*?)"' m = re.search(regex, websource, re.IGNORECASE) profile_picture = m.group(1) logging.info("[ok] got the profile picture from " + realname) except: try: regex = '<img src="(.*?)" alt="' + realname + '"' m = re.search(regex, websource, re.IGNORECASE) profile_picture = m.group(1) logging.info("[ok] got the profile picture from " + realname) except: profile_picture = "http://s.twimg.com/a/1261519751/images/default_profile_1_normal.png" logging.warning("[failed] profile picture regex failed!!!") pass pass try: logging.info("[ok] url of profile picture is " + profile_picture) urllib.urlretrieve(profile_picture, capture) logging.info("[ok] image moved to " + capture) except: logging.warning("[failed] profile picture download failed!!!") pass try: cropme = "convert %s -resize '200' %s" % (capture, capture) os.system(cropme) print cropme logging.info("[ok] image cropped to 200px width") except: logging.error("[failed] image not cropped") pass # sql query try: #q = "INSERT INTO web20suicide.users(`id`,`username`,`friends`,`picture`,`lastwords`,`command`,`t_create`,`email`,`tweets`) VALUES (NULL,%s,%s,%s,%s,%s,CURRENT_TIMESTAMP,%s,%s)" #cursor.execute(q, (username,followers,filename,lastwords,command,email,tweets,)) sendkillermail(capture, username, friends, lastwords, command) logging.info("[ok] user " + username + " added to mysql") try: q2 = "SELECT id FROM web20suicide.users WHERE command='" + command + "' ORDER BY id DESC LIMIT 1" cursor.execute(q2) user_id = cursor.fetchone() user_id = str(user_id.values()) logging.info("fetching raw ID: " + str(user_id)) user_id = user_id.strip("[]L") logging.info("fetching last row ID: " + str(user_id)) except: logging.warning("[failed] to catch last user id") pass except: logging.warning("[failed] mysql insert failed!!") pass except: logging.error("[failed] username, realname, picture failed") pass return following, followers, tweets, username, email, user_id
def getInfo(sel,lastwords,command,email): sel.open("http://www.linkedin.com/home") capturepath = "/var/www/profiles/img/" filename = str(int(time.time())) + ".png" capture = capturepath + filename # get profile name and friends amount with regex-vodoo websource = sel.get_html_source() try: # regex to catch profile image sel.open("http://www.linkedin.com/myprofile?trk=hb_tab_pro") websource2 = sel.get_html_source() m = re.search('<a href="\/myprofile\?trk=nus_stat_photo&goback=%2Ehom"><img src="(.*?)shrink_40_40\/(.*?)"',websource2,re.IGNORECASE) profile_picture = m.group(1) + m.group(2) logging.info("[ok] got the profile picture " + profile_picture) except: profile_picture = "http://static03.linkedin.com/img/icon/icon_no_photo_80x80.png" logging.warning("[failed] 2nd profile picture regex failed, using default one!!!") logging.error(websource2) pass try: logging.info("[ok] url of profile picture is " + profile_picture) urllib.urlretrieve(profile_picture, capture) logging.info("[ok] image moved to " + capture) except: logging.warning("[failed] profile picture download failed!!!") pass try: # modifying pciture so it fits on our wall of fame cropme = "convert %s -resize '200' %s" %(capture,capture) os.system(cropme) print cropme logging.info("[ok] image cropped to 200px width") except: logging.error("[failed] image not cropped") pass try: # regex to catch username m = re.search('<span class="given-name">(.*)</span>\n',websource,re.IGNORECASE) g = re.search('<span class="family-name">(.*)</span>\n',websource,re.IGNORECASE) username = m.group(1) + " " + g.group(1) logging.info("[ok] username logged in as " + username) logging.info("[ok] " + username + " last words are " + lastwords) except: logging.warning("[failed] username regex failed!!!") logging.error(websource) try: m = re.search('<a href="\/myprofile\?trk=hb_pro" title="Edit profile">(.*?)</a>',websource,re.IGNORECASE) username = m.group(1) logging.info("[ok] " + username + " last words are " + lastwords) except: logging.warning("[failed] 2nd username regex failed!!!") pass pass try: sel.open("http://www.linkedin.com/connections?trk=hb_side_connections") websource = sel.get_html_source() time.sleep(2) m = re.search('<strong id="count-showing">(.*?)</strong>',websource,re.IGNORECASE) friends = m.group(1) logging.info("[ok] " + username + " has " + friends + " friends!") except: logging.error(websource) logging.warning("[failed] friendsamount regex failed!!!") friends = "0" pass # sql query try: # q = "INSERT INTO web20suicide.users(`id`,`username`,`friends`,`picture`,`lastwords`,`command`,`t_create`,`email`,) VALUES (NULL,%s,%s,%s,%s,%s,CURRENT_TIMESTAMP,%s)" #cursor.execute(q, (username,friends,filename,lastwords,command,email)) sendkillermail(capture,username,friends,lastwords,command) logging.info("[ok] user " + username + " added to mysql") try: q2 = "SELECT id FROM web20suicide.users WHERE command='" + command + "' ORDER BY id DESC LIMIT 1" cursor.execute(q2) user_id = cursor.fetchone() user_id = str(user_id.values()) user_id = user_id.strip("[]L") logging.info("fetching last row ID: " + str(user_id)) except: logging.warning("[failed] to catch last user id") pass except: logging.warning("[failed] mysql insert failed!!") pass return friends,user_id