askcompu

Untitled

Aug 3rd, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. def ouroboros(site, uri):
  2.     # e621 and twentypercentcooler use the same software
  3.     # TODO: load tag file; compare tags, generate title
  4.     #load a list of unimportant tags from a file. possible regex?
  5.     title = ''
  6.     def get_id(link):
  7.         exp = '(.*)show/(?P<id>[0-9]*)/?'
  8.         return re.search(exp, link).group('id')
  9.     post_id = get_id(uri)
  10.     json_data = web.get('https://{0}.net/post/show.json?id={1}'.format(site, post_id))
  11.     postdata = json.loads(json_data, encoding='utf-8')
  12.     tags = postdata['tags']
  13.  
  14.     ratings = { 's' : 'Safe', 'q' : 'Questionable', 'e' : 'Explicit' }
  15.     if postdata['rating'] in ratings:
  16.         rating = ratings[postdata['rating']]
  17.     else:
  18.         rating = 'Unknown'
  19.     #compare tags to a list of uniportant tags and drop some/most
  20.     tag_file = os.path.expanduser('~/.phenny/boru.py')
  21.     try:
  22.         boru = imp.load_source('boru',tag_file)
  23.     except Exception as e:
  24.         print("Error loading ignore tags: {0} (in head.py)".format(e))
  25.         filteredtags = tags
  26.         listtags = filteredtags.split()
  27.     else:
  28.         filtered = map((lambda x: listtags.replace(x," ")), [boru.ignore_tags])
  29.  
  30.     title = str(filtered)
  31.     title = '{0} {1}'.format(rating.capitalize(),title)
  32.     return title
Advertisement
Add Comment
Please, Sign In to add comment