Advertisement
Guest User

mindfuck

a guest
Nov 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. #!/usr/bin/python
  2. print "Content-type: text/html\n\n"
  3. # -*- coding:Utf-8 -*-
  4. import urllib2
  5.  
  6.  
  7. url = "http://paris.lachainemeteo.com/meteo-france/ville/previsions-meteo-paris-3903-0.php"
  8. data=urllib2.urlopen(url)
  9. data = data.read()
  10.  
  11. start_parse = '<div class="tempe '
  12. end_parse = '<div class="separateur"><!-- --></div>'
  13. temperature, pictogramme = [], []
  14.  
  15. temp_data = [item.split(end_parse) for item in data.split(start_parse)[1:]]
  16.  
  17. start_parse = '<div class="picto">'
  18. end_parse = '" />'
  19. pict_data = [a for a in [item.split(end_parse) for item in data.split(start_parse)]]
  20.  
  21. pictogramme = [ pic.split('.png')[0] for pic in [item[0].split('/')[-1] for item in pict_data] ][1:16]
  22.  
  23. effet = []
  24. for a in pictogramme:
  25.     if a[0] == 'c':
  26.         if '0000' in a:
  27.             effet.append('soleil : ')
  28.         else:
  29.             effet.append('nuage : ')
  30.  
  31.     if a[0] == 'x' or a[0] == 'p':
  32.         effet.append('pluie : ')
  33.  
  34.  
  35. print pictogramme
  36. print len(pictogramme)
  37.  
  38. for item in temp_data:
  39.     temperature.append([temp.split('>')[-1] for temp in item[0].split('&deg;')[:2]])
  40.  
  41. data = [(a+b[0]+'/'+b[1]).replace(' ','%20') for a,b in zip(effet, temperature)][:7]
  42.  
  43. data = '%0a'.join(data)
  44. print data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement