delvin-fil

Для conky

Feb 10th, 2017
440
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3.4
  2. # -*- coding: utf-8 -*-
  3. import urllib, math, json, time, re, warnings,  requests, datetime, ephem
  4. from bs4 import BeautifulSoup
  5. import urllib.request
  6. from datetime import date
  7. from math import radians as rad,degrees as deg
  8.  
  9.  
  10. warnings.filterwarnings("ignore")
  11. localtime = time.localtime(time.time())
  12. z = str(localtime[3])
  13. y = str(localtime[4])
  14.  
  15. cmd = 'sensorsNearby'
  16. uuid = 'YOU_ID'
  17. api_key = 'YOU_API_KEY'
  18. radius = '11'
  19. lat = '54.643600'
  20. lng = '86.198808'
  21. lang = 'ru'
  22. radius = '30'
  23. types = '1,2'
  24.  
  25. headers = {
  26.     'User-Agent': ('Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20100101 '
  27.                   'Firefox/14.0.1'),
  28.     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  29.     'Accept-Language': 'ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3',
  30.     'Accept-Encoding': 'gzip, deflate',
  31.     'Connection': 'keep-alive',
  32.     'DNT': '1'
  33. }
  34.  
  35. WeHtml = requests.get('http://narodmon.ru/api/sensorsNearby?lat=' + lat + '&lng=' + lng + '&radius=' + radius + '&uuid=' + uuid + '&api_key=' + api_key + '&lang=' + lang, headers=headers).text
  36. soup = BeautifulSoup(WeHtml)
  37. soup = str(soup)
  38. soup = re.sub(r'\<[^>]*\>', '', soup)
  39. fact = json.loads(soup)
  40. temp1 = fact['devices'][0]['sensors'][0]['value']
  41. temp2 = fact['devices'][1]['sensors'][0]['value']
  42.  
  43. sredn = str(round(((temp1) + temp2) / 2))
  44.  
  45.  
  46. obs = ephem.Observer()
  47. sun = ephem.Sun()
  48. obs.lat = "54.6436"
  49. obs.long = "86.1988"
  50. obs.date = datetime.datetime.today()
  51. rise_time = obs.next_rising(sun)
  52. set_time = obs.next_setting(sun)
  53. sunrise = ephem.localtime(rise_time).strftime('%H:%M')
  54. sunset = ephem.localtime(set_time).strftime('%H:%M')
  55. moon = ephem.Moon()
  56. m_rise_time = obs.next_rising(moon)
  57. m_set_time = obs.next_setting(moon)
  58. moonrise = ephem.localtime(m_rise_time).strftime('%H:%M')
  59. moonset = ephem.localtime(m_set_time).strftime('%H:%M')
  60.  
  61. g = ephem.Observer()  
  62. g.name='Somewhere'  
  63. g.lat=rad(54.6436)  
  64. g.long=rad(86.1988)  
  65.  
  66. m = ephem.Moon()  
  67.  
  68. g.date = date.today()# local time zone, I'm in UTC+1  
  69. g.date -= ephem.hour
  70. for i in range(1):
  71.     m.compute(g)  
  72.  
  73.     nnm = ephem.next_new_moon(g.date)  
  74.     pnm = ephem.previous_new_moon(g.date)  
  75.     lunation=(g.date-pnm)/(nnm-pnm)  
  76.     symbol=lunation*26
  77.      
  78.     if symbol < 0.2 or symbol > 25.8 :  
  79.         symbol = '1'  
  80.     else:  
  81.         symbol = chr(ord('A')+int(symbol+0.5)-1)  
  82.     mp = str(round(m.phase)) + "%"
  83.     print("${color #AAAAAA}${font Moon\ Phases:size=24:bold}${offset 70}${voffset -15}" + symbol, "${font Ubuntu:size=16:bold}${offset -30}${voffset -8}" + mp)  
  84.     g.date += ephem.minute*15
  85.  
  86. if int(sredn) > 0:
  87.     sredn = "+"+str(sredn)
  88.  
  89. print ("${color red}${font zekton:size=24:bold}${offset 80}${voffset -5}" + sredn + '°')
  90. print ("${color yellow}${voffset -80}${font Ubuntu:size=11}Восход${alignr}${color cyan}Закат")
  91. print ("${voffset -3}${color yellow}" + sunrise + "${alignr}${color cyan}" + sunset)
  92. print ("${color aaaaaa}${voffset -3}Луна${alignr}Луна")
  93. print ("${voffset -3}" + moonrise + "${alignr}" + moonset)
RAW Paste Data