- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
#weather.pyw
from urllib import request
from tkinter import *
import tkinter
import threading
from threading import *
import time
i = 0
active = True
def timerTick( toSleep ):
global active
while active:
refreshCall(0)
time.sleep(toSleep)
def refreshCall(event):
t = Thread(target = refresh)
t.start()
def refresh(*event):
global i
ref['text'] = str(i)
i+=1
r = request
page = str(r.urlopen('http://realmeteo.ru/moscow/1/current/').read())
temperature = page.split('</tr><tr id="num_data"><td>')[1].split(' ')[0]
pressure = page.split(' </td><td>')[1].split(' ')[0]
wind = page.split('<tr id="num_data"><td></td><td>')[1].split(' ')[0]
dest = page.split('<param name="movie" value="/.swf/wind_dir/')[1].split('.swf')[0]
destination = ''
for c in dest:
if c is dest[-1]:
destination += {'N':'Север','S':'Юг','W':'Запад','E':'Восток'}[c]
else:
destination += {'N':'Северо-','S':'Юго-','W':'Западо-','E':'Востоко-'}[c]
#print( temperature, pressure, wind, destination )
l1['text'] = 'Температура: '+temperature
l2['text'] = 'Давление : '+pressure
l3['text'] = 'Сила ветра : '+wind
l4['text'] = 'Направление: '+destination
r = request
page = str(r.urlopen('http://realmeteo.ru/moscow/1/current/').read())
temperature = page.split('</tr><tr id="num_data"><td>')[1].split(' ')[0]
pressure = page.split(' </td><td>')[1].split(' ')[0]
wind = page.split('<tr id="num_data"><td></td><td>')[1].split(' ')[0]
dest = page.split('<param name="movie" value="/.swf/wind_dir/')[1].split('.swf')[0]
destination = ''
for c in dest:
if c is dest[-1]:
destination += {'N':'Север','S':'Юг','W':'Запад','E':'Восток'}[c]
else:
destination += {'N':'Северо-','S':'Юго-','W':'Западо-','E':'Востоко-'}[c]
form = tkinter.Tk()
l1 = Label(form,text='Температура: '+temperature,justify='left'); l1.pack()
l2 = Label(form,text='Давление : '+pressure,justify='left'); l2.pack()
l3 = Label(form,text='Сила ветра : '+wind,justify='left'); l3.pack()
l4 = Label(form,text='Направление: '+destination,justify='left'); l4.pack()
ref = Button(form, text = 'Обновить'); ref.pack()
ref.bind('<Button-1>',refreshCall)
timerThread = Thread(target = timerTick, args=(5,))
timerThread.start()
form.mainloop()
active = False
Угадайте, с какого языка пересел автор. (не пэхапэ)