Download Term Report PDF - VTechWorks

Transcript
from operator import itemgetter from contextlib import closing requests.packages.urllib3.disable_warnings() headers = {'User-­‐Agent': 'Digital Library Research Laboratory (DLRL)'} def visible(element): if element.parent.name in ['style', 'script', '[document]', 'head']: return False return True thresh =1 archiveID = sys.argv[1].split(".")[0] tweetFile = sys.argv[1] tweets = [] f = open(tweetFile,"r") us = f.readlines() f.close() for l in us[1:]: l = l.strip() p = l.split(",") t = p[0] tweets.append(t) docs=[] print "tweets is read from File" # Extract short URLs from Tweets #-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐ shortURLsList =[] #for row in cursor.fetchall(): for line in tweets: #line = row[1] regExp = "(?P<url>https?://[a-­‐zA-­‐Z0-­‐9\./-­‐]+)" url_li = re.findall(regExp, line) # find all short urls in a single tweet while (len(url_li) > 0): shortURLsList.append(url_li.pop()) print "short Urls extracted: ", len(shortURLsList) surls = [] for url in shortURLsList: i = url.rfind("/") if i+1 >= len(url): continue p = url[i+1:] if len(p) < 10: continue while url.endswith("."): 60