def initailizeUserDictByURL(url, count=5): user_dict = {} for urlposts in pydelicious.get_urlposts(url=url)[1 : count+1]: user = urlposts['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag,count=5): user_dict = {} all_items = {} # get the top count' popular posts for p1 in get_popular(tag=tag)[0:count]: # find all users who posted this for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict.setdefault(user,{}) # get user posts for i in range(3): try: posts = get_userposts(user) break except: print "Failed user "+user+", retrying" time.sleep(4) for post in posts: url = post['href'] user_dict[user][url] = 1.0 all_items[url] = 1 #fill in missing items with 0 [ratings.setdefault(item,0.0) for item in all_items for ratings in user_dict.values()] return user_dict
def initializeUserDict(tag, count = 5): usr_dict = {} for most_popular in get_popular(tag = tag)[0 : count]: for person in get_urlposts(most_popular['href']): usr = person['user'] usr_dict[usr] = {} return usr_dict
def initializeUserDict(tag, count=5): userDict = {} for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1['url']): user = p2['user'] userDict[user] = {} return userDict
def initialize(tag,count=5): user_dict = {} for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} for p1 in tag[0:count]: for p2 in get_urlposts(p1): user = p2["user"] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1["url"]): user = p2["user"] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict={} # 获取前count个最受欢迎的张 for p1 in get_popular(tag = tag)[0:count]: for p2 in get_urlposts(p1['href']): user=p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag ,count = 5): user_dict = {} #get the top count popular posts for p1 in get_popular(tag = tag)[0:count]: for p2 in get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} return user_dict
def initUserDict(tag, count=5): user_dict = {} for p1 in py.get_popular(tag)[0:count]: for p2 in py.get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initialze_user_dict(tag, count=5): user_dict = {} # 获取前count个最受欢迎的链接张贴记录 for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1['url']): # 此处与书中不同,现在返回字典的'href' 键已经改为 'url' user = p2['user'] user_dict[user] = {} return user_dict
def initlizeUserDict(tag, count=5): user_dict = {} #获取所有用户都提交过的链接 for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initialize_user_dict(tag,count=5): user_dict={} # Get the top "count" popular posts for p1 in pydelicious.get_popular(tag=tag)[0:count]: # Find all users who posted the same post url for p2 in pydelicious.get_urlposts(p1['url']): user=p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag,count=5): user_dict={} # count개의 인기 게시물을 얻음 for p1 in get_popular(tag=tag)[0:count]: # 이 게시물을 올린 모든 사용자를 얻음 for p2 in get_urlposts(p1['href']): user=p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} # отримати рахунок найпопулярніших лінків for p1 in get_popular(tag=tag)[0:count]: # знайти всіх користувачів, які зберегли цей лінк for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag,count=5): user_dict={} # get the top count' popular posts for p1 in get_popular(tag=tag)[0:count]: # find all users who posted this for p2 in get_urlposts(p1['url']): user=p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag,count=5): user_dict={} #获取前count个最受欢迎的链接张贴记录 for p1 in get_popular(tag=tag)[0:count]: #查看所有张贴该链接的用户 for p2 in get_urlposts(p1['herf']): user=p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag,count=5): user_dict={} #get the top "count" popular posts for p1 in get_popular(tag=tag)[0:count]: #from api #find all users who posted this for p2 in get_urlposts(p1['href']): user=p2['user'] user_dict[user]={} #looking at a key:value pair? return user_dict
def initializeUserDict(tag, count=30): # 引数に tag と count をとる、count の指定がなければ 5 user_dict = {} # popular な投稿を 0 から count 番目まで取得 for p1 in get_popular(tag=tag)[0:count]: # このリンクを投稿したすべてのユーザを取得 for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initlizeUserDict(tag, count = 5): user_dict = {} #获取所有用户都提交过的链接 for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag, count=5): user_dict={} for p1 in get_popular(tag=tag)[0:count]: # get_urlposts()는 주어진 url에 대한 모든 게시글을 리턴 for p2 in get_urlposts(p1['url']): # 리턴된 게시글들의 '유저이름'을 가져옴. '유저이름'의 value는 일단 null로 둠 user=p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag,count=2): user_dict={} # get the top count' popular posts for p1 in get_popular(tag=tag)[0:count]: # find all users who posted this for p2 in get_urlposts(p1['href']): user=p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag, count=5): user_dict={} # отримати рахунок найпопулярніших лінків for p1 in get_popular(tag=tag)[0:count]: # знайти всіх користувачів, які зберегли цей лінк for p2 in get_urlposts(p1['href']): user=p2['user'] user_dict[user]={} return user_dict
def initialize_user_dict(tag, count=5): user_dict = {} # get the top count' posts for p1 in get_tagposts(tag=tag)[0:count]: # find all users who posted this for p2 in get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} #获取当前count个最受欢迎的链接张贴记录 for p1 in get_popular(tag=tag)[0:count]: #查找所有张贴该链接的用户 for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} # count개의 인기 게시물을 얻음 for p1 in get_popular(tag=tag)[0:count]: # 이 게시물을 올린 모든 사용자를 얻음 for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} # 获取某tag下前count个最受欢迎的url post记录 for p1 in get_popular(tag=tag)[0:count]: # 获取所有post该url的用户 for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} # get top "count" of popular posts: for p1 in get_popular(tag=tag)[0:count]: # Find the users who poseted them: for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count = 5): user_dict = {} # read in top "count" popular posts for p1 in get_popular(tag = tag)[0:count]: #find all users who posted this for p2 in get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag,count = 5): user_dict = {} #获取前count个最受欢迎的链接张贴记录 for p1 in get_popular(tag=tag)[0:count]: #查找所有张贴记录的用户 for p2 in get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} #得到一个包含用户的空字典 return user_dict
def initializeUserDict(tag, count=5): user_dict = {} for p1 in get_popular(tag=tag)[0:count]: #find all users that posted this for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict={} #get count most popular links for p1 in get_popular(tag=tag)[0:count]: #find all users saved this link for p2 in get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): """Grabs the user ids of active del.icio.us users.""" user_dict = {} # get top `count` popular posts... for p1 in get_popular(tag=tag)[0:count]: # ...and add all users who posted them for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def _init_user_dict(self, count=5): user_dict = {} for p1 in pydelicious.get_popular(tag=self._tag)[0:count]: for p2 in pydelicious.get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} if __debug__: print(user_dict) self._usr_dict = user_dict
def initialize_user_dict(tag, count=5): """ Returns: length n dict of users: empty dict pairs. """ user_dict = {} for post in get_popular(tag=tag)[:count]: for url in get_urlposts(post['url']): user = url['user'] user_dict[user] = {} return user_dict
def initialiseUserDict(tag,count=5): user_dict={} for p1 in pydelicious.get_popular(tag=tag): print p1 for p2 in pydelicious.get_urlposts(p1['url'])[0:count]: print p2 user = p2['user'] if len(user): user_dict[user]={} return user_dict
def initializeUserDictByTag(tag, count=5): user_dict = {} # 获取前count个最受欢迎的链接张贴记录 for p1 in pydelicious.get_popular(tag=tag)[0:count] : # 查找所有张贴该链接的用户 for p2 in pydelicious.get_urlposts(p1['url']) : user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag, count = 5): '''Get a list of users who recently posted a popular link.''' user_dict = {} # get the top count popular posts for p1 in get_popular(tag = tag)[0:count]: # find all users who posted this for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict.setdefault(user, {}) return user_dict
def initUserDict(tag, count = 5): user_dict = {} # get the top count popular posts for p1 in pydelicious.get_popular(tag=tag)[0:count]: # find all users who posted this # print pydelicious.get_urlposts(p1['url']) for p2 in pydelicious.get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} return user_dict
def initUserDict(tag, n): user_dict={} #Fåtop count' populära posts for p1 in get_popular(tag)[0:n]: #Hitta alla användare som postade den for p2 in get_urlposts(p1['href']): user=p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag,count=5): user_dict={} # get popular blog posts for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1['href']): user=p2['user'] if user: user_dict[user]={} return user_dict
def initializeUserDict(tag, count=5): user_dict={} # popularな投稿をcount番目まで取得 for p1 in get_popular(tag=tag)[0:count]: # このリンクを投稿したすべてのユーザを取得 for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user]={} return user_dict
def initializeUserDict(tag, count=5): suer_dict = {} a = get_popular(tag=tag)[0:count] print a for p1 in a: # Find all user who posted it for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} return user_dict
def initialize_object_dict(self, tag, count=5): """ Initialize object (user) dict with users from the popular posts for tag """ for popular in get_popular(tag=tag)[0:count]: for posts in get_urlposts(popular['url']): object = posts['user'] if self.verbose: print object self.object_dict[object] = dict()
def initializeUserDict(tag, count=5): user_dict = {} # get the top count' popular posts for p1 in get_popular(tag=tag)[0:count]: for p2 in get_urlposts(p1['url']): user = p2['user'] #print(p1['url'] + ' ' + user) user_dict[user] = {} return user_dict
def initializeUserDict(tag, count=5): user_dict = {} for p1 in get_popular(tag=tag)[0:count]: print(p1) if (not p1["href"]): break for p2 in get_urlposts(p1["href"]): user = p2['user'] user_dict[user] = {} return user_dict
def initializeUserDict(tag='programming', count=1): user_dict = {} # get the top count' popular posts for p1 in get_popular(tag=tag)[0:count]: # find all users who posted this print "working on count", count pst = get_urlposts(p1['url']) print "pst len", len(pst) for p2 in pst: user = p2['user'] user_dict[user] = {} print "user=" + user return user_dict
def initializeUserDict(tag, count=5): user_dict = {} try: # get the top count popular posts for p1 in get_popular(tag=tag)[0:count]: # Find all users who posted this for p2 in get_urlposts(p1['href']): user = p2['user'] user_dict[user] = {} # except Exception: print('function') return user_dict
def getItemsTags(user_dict,n=5): urltag_dict = {} all_tags = {} count = 0 url_limit_per_user = 5 break_flag = 0 for user in user_dict: if(count==n): break_flag = 1 break count += 1 url_count = 0 for url in user_dict[user]: #print "Url["+url+"]" if(url_count>url_limit_per_user): break; url_count += 1 retry_count = 0 for i in range(3): try: posts=get_urlposts(url) break except: print "Failed url "+url+", retrying" time.sleep(4) retry_count +=1 if(retry_count>=3): continue for post in posts[0:10]: #print post['tags'] tag_count = 0 for tag in post['tags'].split(): #print "working with tag %s" % tag all_tags[tag]=1 urltag_dict.setdefault(url,{}) urltag_dict[url][tag]=1.0 tag_count+=1 #print "\\ttags %d" %tag_count #break print "Collecting tags finished" # Fill in missing tags with 0 for tags_ratings in urltag_dict.values(): for tag in all_tags: if tag not in tags_ratings: tags_ratings[tag]=0.0 return urltag_dict
def initializeUserDict(tag, count=5): user_dict = {} #获取前count个最受欢迎的张贴记录 for p1 in get_popular(tag=tag)[0:count]: print "Got a post !" #查找所有张贴该记录的用户 #原来的API已经改了,不用href,而是url for i in range(3): try: for p2 in get_urlposts(p1['url']): user = p2['user'] user_dict[user] = {} break except: print "Failed....retrying" time.sleep(4) return user_dict
def fillItem(user_dict): all_item = {} for user in user_dict: for i in range(3): try: posts = get_urlposts(user) break except: print "Failed user " + user + ", retrying" time.sleep(4) for post in posts: url = post['href'] user_dict[user][url] = 1.0 all_item[url] = 1 for ratings in user_dict.values: for item in all_item: if item not in ratings: ratings[item] = 0.0
def fillItems(user_dict): all_items = {} #查找所有用户都提交过的链接 for user in user_dict: for i in range(3): try: posts = get_urlposts(user) break except: print "failed user " + user + ", retrying" time.sleep(4) for post in posts: url = post['href'] user_dict[user][url] = 1.0 all_items[url] = 1 #用0填充缺失项 for ratings in user_dict.values(): for item in all_items: if item not in ratings: ratings[item] = 0.0
def fill_items(user_dict): all_items = {} # 查找所有用户都提交过的链接 for user in user_dict: for i in range(3): try: posts = get_urlposts(user) break except: print 'Failed user' + user + ', retrying' time.sleep(4) for post in posts: url = post['url'] user_dict[user][url] = 1 all_items[url] = 1 # 用0填充缺失的内容 for ratings in user_dict.values(): for item in all_items: if item not in ratings: ratings[item] = 0
def fillitems(user_dict): all_items = {} #Find links posted by all users for user in user_dict: for i in range(3): try: posts = get_urlposts(user) break except: print "Failed user " + user + ", retrying" time.sleep(4) for post in posts: url = post['url'] user_dict[user][url] = 1.0 all_items[url] = 1 #Fill in missing items with 0 for ratings in user_dict.values(): for item in all_items: if item not in ratings: ratings[item] = 0.0
def fillItems(user_dict): all_items = {} # Finding links posted by the users in user_dict: for user in user_dict: # Make only three attempts to get data: for i in range(3): try: posts = get_urlposts(user) break except: print "Failed user" + user + ", trying again" time.sleep(4) for post in posts: url = post['fref'] user_dict[user][url] = 1.0 all_items[url] = 1 # Fill in missing items with 0: for ratings in user_dict.values(): for item in all_items: if item not in ratings: ratings[item] = 0.0
def initUserDict(tag): user_dict = {} popular_links = [ #u'http://coursera.org/', u'http://ibm.com/', ] for url in popular_links: # The get_urlposts API returns last 30 people who post the link while (True): try: posts = get_urlposts(url) print 'fetch {0} users from {1}.'.format(len(posts), url) break except: print 'Error on {0}, retrying'.format(url) time.sleep(4) for post in posts: user = post['user'] if user.strip() != '': user_dict[user] = {} print url return user_dict
def initializeUserDict(tag, count=5, cache_dict=True): #get_popular doesn't work any more. Getting by tag #return [url_post['user'] for item in get_tagposts(tag=tag)[0:count] for url_post in get_urlposts(item['url'])] #from hashlib import md5 #print md5('http://usingtechnologybetter.com/chrome-extensions-for-teachers/').hexdigest() user_dict_cache_file = "user_dict.p" if cache_dict and exists(user_dict_cache_file): print "Reading the user_dict from cache file", user_dict_cache_file cache_file = open(user_dict_cache_file, "rb") user_dict = load(cache_file) cache_file.close() else: user_dict = dict([(url_info['user'], {}) for item in get_tagposts(tag=tag)[0:count] for url_info in get_urlposts(item['url']) if url_info['user'] != '']) if cache_dict: print "Writing the user_dict to cache file", user_dict_cache_file cache_file = open(user_dict_cache_file, "wb") dump(user_dict, cache_file) cache_file.close() return user_dict