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 build_tag_matrix(tags):
    """
    Given a list of bookmarks returns a matrix with
    tags as columns and urls as rows.

    Returns: tags, urls, matrix
    """
    bookmarks = []
    for tag in tags:
        marks = get_popular(tag=tag)
        for bookmark in marks:
            url = bookmark["url"]
            tags = bookmark["tags"]
            bookmarks.append({"url": url, "tags": tags})

    tag_list = set(tag for tag in bookmark["tags"] for bookmark in bookmarks)
    url_list = []
    matrix = []
    for bookmark in bookmarks:
        row = []
        for tag in tag_list:
            row.append(1 if tag in bookmark["tags"] else 0)
        url_list.append(bookmark["url"])
        matrix.append(row)
    return tag_list, url_list, matrix
Esempio n. 3
0
def build_tag_matrix(tags):
    """
    Given a list of bookmarks returns a matrix with
    tags as columns and urls as rows.

    Returns: tags, urls, matrix
    """
    bookmarks = []
    for tag in tags:
        marks = get_popular(tag=tag)
        for bookmark in marks:
            url = bookmark["url"]
            tags = bookmark["tags"]
            bookmarks.append({"url": url, "tags": tags})

    tag_list = set(tag for tag in bookmark["tags"] for bookmark in bookmarks)
    url_list = []
    matrix = []
    for bookmark in bookmarks:
        row = []
        for tag in tag_list:
            row.append(1 if tag in bookmark["tags"] else 0)
        url_list.append(bookmark["url"])
        matrix.append(row)
    return tag_list, url_list, matrix
Esempio n. 4
0
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 get_popular(tag=tag)[0:count]:
        for p2 in get_userposts(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["url"]):
            user = p2["user"]
            user_dict[user] = {}
    return user_dict
Esempio n. 7
0
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):
	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
Esempio n. 9
0
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
Esempio n. 10
0
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']
            if len(user) > 0:
                user_dict[user] = {}
    return user_dict
Esempio n. 11
0
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
Esempio n. 13
0
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
Esempio n. 14
0
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
Esempio n. 15
0
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 initialize_user_dict(tag, count=5):
	user_dict = {}
	# Get the top count popular post
	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
Esempio n. 17
0
def initializeUserDict(tag, count=5):
    """docstring for initializeUserDict"""
    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 get_popular(tag=tag)[0:count]:
        # знайти всіх користувачів, які зберегли цей лінк
        for p2 in get_urlposts(p1['href']):
            user = p2['user']
            user_dict[user] = {}
        return user_dict
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
0
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
Esempio n. 22
0
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={}
  # 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
Esempio n. 24
0
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
Esempio n. 25
0
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
Esempio n. 26
0
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
Esempio n. 27
0
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['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 = {}
    #获取当前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
Esempio n. 31
0
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
Esempio n. 32
0
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
Esempio n. 33
0
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
Esempio n. 34
0
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
Esempio n. 36
0
    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
Esempio n. 37
0
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
Esempio n. 38
0
    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
Esempio n. 39
0
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 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
Esempio n. 41
0
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
Esempio n. 42
0
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 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
Esempio n. 44
0
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
Esempio n. 45
0
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
Esempio n. 46
0
 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()
Esempio n. 47
0
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
Esempio n. 48
0
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
Esempio n. 49
0
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
Esempio n. 50
0
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
Esempio n. 51
0
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
Esempio n. 52
0
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
Esempio n. 53
0
def build_tag_dict(tags):
	all_items = {}
	tags_dict = {}
	# Find links posted by all get_user
	for tag in tags:
		bookmarks = get_popular(tag=tag)
		for bookmark in bookmarks:
			url = bookmark["url"]
			for tag in bookmark["tags"]:
				tags_dict.setdefault(tag, {})
				tags_dict[tag][url] = 1.0
				all_items[url] = 1


	# Fill in missing items with zero.
	for ratings in tags_dict.values():
		for item in all_items:
			if item not in ratings:
				ratings[item] = 0.0
	return tags_dict
Esempio n. 54
0
import pydelicious
from urllib import urlencode
from urllib2 import urlopen
# import get_userposts,get_popular,get_urlposts
pydelicious.get_popular(tag="programming")
# pydelicious.get_userposts('dorsia')

# 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
Esempio n. 55
0
def cls():
    if os.name == 'posix':
        os.system('clear')
    else:
        os.system('cls')


cls()

# como o módulo pydelicious pode não estar instalado coloquei este try/except
try:
    import pydelicious
except ImportError:
    print(" ")
    print(" você tem que instalar primeiro a biblioteca pydelicious")
    print("")
    print(" sudo aptitude install python-setuptools")
    print(
        " sudo easy_install http://pydelicious.googlecode.com/files/pydelicious-0.6.zip"
    )
    print(" ")
    sys.exit(1)

if len(sys.argv) != 2:
    print('Uso: %s tag' % sys.argv[0])
    sys.exit(1)

populares = pydelicious.get_popular(tag=str(sys.argv[1]))
# print("\n".join([ x.get('url') for x in populares] ))
print(populares)
def initUserDict(tag, count=5):
    user_dict = {}
    for post in get_popular(tag=tag)[0:count]:
        for post2 in get_urlposts(post['url']):
            user_dict[post2['user']] = {}
    return user_dict
Esempio n. 57
0
                time.sleep(4)
        for post in posts:
            url = post['url']
            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


#全局测试代码
if 0:
    pl = get_popular('programming')
    url = pl[0]['url']
    for item in pl:
        url = item['url']
        print url
    for item in pl:
        url = item['url']
        print url
        print get_urlposts(url)
    print get_urlposts('http://www.holub.com/goodies/uml/')
    #print url
# print get_urlposts(url)

#全局测试代码二
if 0:
    delusers = initializeUserDict('programming')
from pydelicious import get_popular, get_urlposts, get_userposts
print(get_popular(tag="programing"))
Esempio n. 59
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/2/26 16:19
# @Author : Shuqi.qin
# @Site :
# @File : test.py
# @Software: PyCharm

import recommendations as rc

res1 = rc.sim_distance(rc.critics, "Lisa Rose", "Gene Seymour")

res2 = rc.sim_pearson(rc.critics, "Lisa Rose", "Gene Seymour")

res3 = rc.topMatches(rc.critics, "Toby", n=3)

res4 = rc.getRecommendationsBaseOnPersonSimilarity(rc.critics, "Toby")

print 'over'

import pydelicious

print pydelicious.get_popular(tag='programming')