Guest User

Untitled

a guest
Jan 28th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. # -*- coding:Utf-8 -*-
  2. import urllib2 as get
  3.  
  4. vdm_start = 'class="fmllink">Aujourd'
  5. vdm_end = '</a></p><div class="date">'
  6.  
  7. def get_quote():
  8.     quote = get.urlopen('http://www.viedemerde.fr/aleatoire').read()
  9.     quote = [a.split(vdm_end)[:-1] for a in quote.split(vdm_start)[1:]]
  10.     for i, item in enumerate(quote):
  11.         item = [a.split('>')[1] if '>' in a else a for a in item[0].split('</a><a')]
  12.         quote[i] = 'Aujourd'+''.join(item)
  13.     return quote
  14.  
  15. with open('vdm.txt', 'r') as f: vdm= f.read()
  16. vdm = vdm.split('\n') if vdm else get_quote()
  17. while not raw_input(''):
  18.     print '\n',vdm.pop(0),'\n'
  19.     if not vdm: vdm = get_quote()
  20. with open('vdm.txt', 'w') as file:file.write('\n'.join(vdm))
Advertisement
Add Comment
Please, Sign In to add comment