lolamontes69

Ch2 Ex2-Programming Collective Intelligence

May 19th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. from pydelicious import DeliciousAPI
  2. from pydelicious import *
  3. from getpass import getpass
  4. from time import sleep
  5.  
  6. def invert_dict(d):
  7.     inverse = dict()
  8.     for key in d:
  9.         val = d[key]
  10.         if val not in inverse:
  11.             inverse[val] = [key]
  12.         else:
  13.             inverse[val].append(key)
  14.     return inverse
  15.  
  16. def main():
  17.     username = str(raw_input('Username:'))
  18.     pwd = getpass('Pwd:')
  19.     a = DeliciousAPI(username, pwd)
  20.  
  21.     # Get list of tagged urls
  22.     frogs = get_tagposts('programming')
  23.     sleep(2)
  24.  
  25.     # Put tagged urls into list
  26.     list1 = []
  27.     for a in range(len(frogs)):
  28.         count = 0
  29.         for b in frogs[a]:
  30.             count += 1
  31.             if count == 4:
  32.                 list1.append(frogs[a][b])
  33.  
  34.     # Get all instances of urls
  35.     dic2 = {}
  36.     for tadpoles in list1:
  37.         spawn = get_urlposts(tadpoles)
  38.  
  39.     # Put tags into histogram
  40.         for a in range(len(spawn)):
  41.             count = 0
  42.             for b in spawn[a]:
  43.                 count += 1
  44.                 if count == 3:
  45.                     if (spawn[a][b] not in dic2):
  46.                         dic2[spawn[a][b]] = 1
  47.                     else:
  48.                         dic2[spawn[a][b]] = dic2[spawn[a][b]] + 1
  49.  
  50.     # Invert the histogram and print most often first
  51.     dic3 = invert_dict(dic2)
  52.     # Print results
  53.     res = dic3.keys()
  54.     res.sort()
  55.     res.reverse()
  56.     print res
  57.     for z in res:
  58.         print dic3[z],"appears",z,"times"
  59.  
  60. if __name__ == "__main__":
  61.     main()
  62.  
  63. """
  64. Tag similarity. Using the del.icio.us API, create a dataset of tags and items. Use this to calculate similarity between tags and see if you can find any that are almost identical. Find some items that could have been tagged programming but were not.
  65. Ps Dont know why I used frog related variables
  66. """
Advertisement
Add Comment
Please, Sign In to add comment