-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeliciousrec.py
More file actions
33 lines (29 loc) · 910 Bytes
/
deliciousrec.py
File metadata and controls
33 lines (29 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from numpy import *
from matplotlib.pyplot import *
from pydelicious import get_popular,get_userposts,get_urlposts
import time,pdb
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 fillItems(user_dict):
all_items = {}
for user in user_dict:
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['url']
user_dict[user][url]=1.0
all_items[url]=1
for ratings in user_dict.values():
for item in all_items:
if item not in ratings:
ratings[item] = 0.