Advertisement
delvin-fil

Untitled

Feb 10th, 2017
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.03 KB | None | 0 0
  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. from pprint import pprint
  6. import urllib.request
  7. from datetime import date
  8. from math import radians as rad,degrees as deg
  9.  
  10.  
  11. warnings.filterwarnings("ignore")
  12. localtime = time.localtime(time.time())
  13. z = str(localtime[3])
  14. y = str(localtime[4])
  15.  
  16. cmd = 'sensorsNearby'
  17. uuid = '6ce5e6b78477f27084cc524599fc5930'
  18. api_key = '09XImZqvP6g6U'
  19. radius = '11'
  20. lat = '54.643600' # Home 9
  21. lng = '86.198808' # Home 9
  22. lang = 'ru'
  23. radius = '30'
  24. types = '1,2'
  25.  
  26. #http://maps.googleapis.com/maps/api/elevation/xml?locations=86.198808,54.643600&sensor=true
  27. headers = {
  28.     'User-Agent': ('Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20100101 '
  29.                   'Firefox/14.0.1'),
  30.     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  31.     'Accept-Language': 'ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3',
  32.     'Accept-Encoding': 'gzip, deflate',
  33.     'Connection': 'keep-alive',
  34.     'DNT': '1'
  35. }
  36.  
  37. 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
  38. soup = BeautifulSoup(WeHtml)
  39. soup = str(soup)
  40. soup = re.sub(r'\<[^>]*\>', '', soup)
  41. fact = json.loads(soup)
  42. temp1 = fact['devices'][0]['sensors'][0]['value']
  43. temp2 = fact['devices'][1]['sensors'][0]['value']
  44. #davl = str(round(fact['devices'][0]['sensors'][1]['value']))
  45. #a = fact['devices'][0]['location']
  46. sredn = str(round(((temp1) + temp2) / 2))
  47. #print ("${color cyan}${font ubuntu:size=11}${alignr 75}${voffset -25}" + davl + ' мм.р.c.')
  48. #print ("${color cyan}${font ubuntu:size=11}${alignr 85}${voffset -28}" + a)
  49.  
  50.  
  51. obs = ephem.Observer()
  52. sun = ephem.Sun()
  53. obs.lat = "54.6436"
  54. obs.long = "86.1988"
  55. obs.date = datetime.datetime.today()
  56. rise_time = obs.next_rising(sun)
  57. set_time = obs.next_setting(sun)
  58. sunrise = ephem.localtime(rise_time).strftime('%H:%M')
  59. sunset = ephem.localtime(set_time).strftime('%H:%M')
  60. moon = ephem.Moon()
  61. m_rise_time = obs.next_rising(moon)
  62. m_set_time = obs.next_setting(moon)
  63. moonrise = ephem.localtime(m_rise_time).strftime('%H:%M')
  64. moonset = ephem.localtime(m_set_time).strftime('%H:%M')
  65.  
  66. g = ephem.Observer()  
  67. g.name='Somewhere'  
  68. g.lat=rad(54.6436)  # lat/long in decimal degrees  
  69. g.long=rad(86.1988)  
  70.  
  71. m = ephem.Moon()  
  72.  
  73. g.date = date.today()# local time zone, I'm in UTC+1  
  74. g.date -= ephem.hour # always everything in UTC  
  75. #print (g.date, ephem.localtime(g.date).time().strftime("%H%M"))  
  76. for i in range(1): # compute position for every 15 minutes  
  77.     m.compute(g)  
  78.  
  79.     nnm = ephem.next_new_moon(g.date)  
  80.     pnm = ephem.previous_new_moon(g.date)  
  81.     # for use w. moon_phases.ttf A -> just past  newmoon,  
  82.     # Z just before newmoon  
  83.     # '0' is full, '1' is new  
  84.     # note that we cannot use m.phase as this is the percentage of the moon  
  85.     # that is illuminated which is not the same as the phase!  
  86.     lunation=(g.date-pnm)/(nnm-pnm)  
  87.     symbol=lunation*26
  88.      
  89.     if symbol < 0.2 or symbol > 25.8 :  
  90.         symbol = '1'  # new moon  
  91.     else:  
  92.         symbol = chr(ord('A')+int(symbol+0.5)-1)  
  93.  
  94.     #print(ephem.localtime(g.date).time(), deg(m.alt),deg(m.az), ephem.localtime(g.date).time().strftime("%H%M"),  m.phase,symbol)
  95.     mp = str(round(m.phase)) + "%"
  96.     print("${color #AAAAAA}${font Moon\ Phases:size=24:bold}${offset 70}${voffset -15}" + symbol, "${font Ubuntu:size=16:bold}${offset -30}${voffset -8}" + mp)  
  97.     g.date += ephem.minute*15
  98.  
  99. if int(sredn) > 0:
  100.     sredn = "+"+str(sredn)
  101.  
  102. print ("${color red}${font zekton:size=24:bold}${offset 80}${voffset -5}" + sredn + '°')
  103. print ("${color yellow}${voffset -80}${font Ubuntu:size=11}Восход${alignr}${color cyan}Закат")
  104. print ("${voffset -3}${color yellow}" + sunrise + "${alignr}${color cyan}" + sunset)
  105. print ("${color aaaaaa}${voffset -3}Луна${alignr}Луна")
  106. print ("${voffset -3}" + moonrise + "${alignr}" + moonset)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement