def index(): title = "Homepage" return render_template("index.html", title=title, location=get_location(), temperature=get_temperature(), city_info=get_city_info())
def get_weather(): if request.method == 'POST': data = request.json location = get_location(data['city']) return { 'temperature': get_temperature(location), 'wiki': get_city_info(data['city']) }
def on_run(code, output, properties): f = weather.get_temperature("Miami, FL") c = (f - 32) / 1.8 if not output: return "You have to print the temperature in Farenheit and Celsius." elif "weather.get_temperature(\"Miami, FL\")" not in code: return "You need to request Miami's current temperature." elif "celsius = (fahrenheit - 32) / 1.8" not in code: return "You are not converting the temperature to celsius using the right formula." elif (str(f)+"\n" in output) or (str(c)+"\n" in output): return True else: return "You must print Miami's temperature in both scales."
def on_run(code, output, properties): f = weather.get_temperature("Miami, FL") c = (f - 32) / 1.8 if not output: return "You have to print the temperature in Farenheit and Celsius." elif "weather.get_temperature(\"Miami, FL\")" not in code: return "You need to request Miami's current temperature." elif "celsius = (fahrenheit - 32) / 1.8" not in code: return "You are not converting the temperature to celsius using the right formula." elif (str(f) + "\n" in output) or (str(c) + "\n" in output): return True else: return "You must print Miami's temperature in both scales."
def play_chimes(hour: int, minute: int) -> None: global temp global PLAY_STATE if not PLAY_STATE: oldtemp = temp temp = weather.get_temperature() if temp < -100: temp = oldtemp return global qh global hh global tqh global hc global hcc if minute == 15: qh.play() sleep(qh.get_length()) elif minute == 30: hh.play() sleep(hh.get_length()) elif minute == 45: tqh.play() sleep(tqh.get_length()) else: hc.play() sleep(hc.get_length()) count = hour % 12 if count == 0: count = 12 for i in range(count): hcc.play() sleep(4.29) oldtemp = temp temp = weather.get_temperature() if temp < -100: temp = oldtemp return
def __init__(self, parent, *args, **kwargs): Frame.__init__(self, parent, bg='black') # Init a label self.temp = weather.get_temperature() self.tempLabel = Label(self, font=('Helvetca', 40), fg="white", bg="black") self.tempLabel.pack(side=TOP, anchor=E) self.condition = weather.get_condition() self.conditionLabel = Label(self, text=dictweather[self.condition], font=('Helvetca', 40), fg="white", bg="black") self.conditionLabel.pack(side=TOP, anchor=E) self.tick()
import weather, temp, datetime, time GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(26, GPIO.OUT) def on(): GPIO.output(26, GPIO.LOW) def off(): GPIO.output(26, GPIO.HIGH) t = weather.get_temperature() try: while True: time_now = datetime.datetime.now() if (time_now.minute == 0 and time_now.second == 0): t = weather.get_temperature() if (t[0] >= 30): set_temp = (t[0] * 0.9) + (t[1] * 0.05) else: set_temp = (t[0] * 1.1) + (t[1] * 0.05) read = temp.read_temp() print(set_temp, read) sleep_time = 1 - (1 / (set_temp - read)) on() time.sleep(sleep_time) off()
def main(): global PLAY_STATE PLAY_STATE = True # Initialize the sound mixer.pre_init() mixer.init() # Load the sounds # Set this to the directory you installed the app in chimedir = "/home/pi/Chimes/" # Download the chime sounds you want to use and rename # these sound file names to match your sounds. global qh qh = mixer.Sound("%sQuarterHourChime.wav" % chimedir) global hh hh = mixer.Sound("%sHalfHourChime.wav" % chimedir) global tqh tqh = mixer.Sound("%s3QuarterChime.wav" % chimedir) global hc hc = mixer.Sound("%sHourChime.wav" % chimedir) global hcc hcc = mixer.Sound("%sHourCountChime.wav" % chimedir) global ChimeVolume ChimeVolume = 40 set_volume(ChimeVolume) # Initialize the buttons GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) for pin in audio_config: GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(pin, GPIO.FALLING, callback=gpio_event, bouncetime=150) # Initialize the weather global temp temp = weather.get_temperature() if temp < -100: temp = 0 # Initialize the image # Download the image you want to use as a backgroound # and rename this variable appropriately. image_file = f"{chimedir}/bigben.jpg" # Change this to point at the font yuou want to use FONT = "pygame/examples/data/sans.ttf" ttf = ImageFont.truetype( FONT, 50, ) dttf = ImageFont.truetype( FONT, 40, ) # Create ST7789 LCD display class. disp = ST7789.ST7789( rotation=90, port=0, cs=1, dc=9, backlight=13, spi_speed_hz=90000000, ) # Initialize display. disp.begin() WIDTH = disp.width HEIGHT = disp.height # Load an image. image = Image.open(image_file) # Resize the image and display the initial clock image = image.resize((WIDTH, HEIGHT)) draw = ImageDraw.Draw(image) curtime = localtime() ap = "AM" if curtime.tm_hour < 12 else "PM" hour = curtime.tm_hour % 12 if hour == 0: hour = 12 fahr = int((temp * 9.0) / 5.0) + 32 draw.text((20, 170), f"{fahr}F {temp:.1f}C", font=dttf) draw.text((15, 90), f"{hour:02}:{curtime.tm_min:02} {ap}", font=ttf) date = localtime() # People outside the US will want to change this format draw.text( (20, 20), f"{date.tm_mon:02}/{date.tm_mday:02}/{date.tm_year}", font=dttf, ) disp.display(image) while True: image = Image.open(image_file) image = image.resize((WIDTH, HEIGHT)) draw = ImageDraw.Draw(image) while localtime().tm_sec > 0: sleep(1) curtime = localtime() hour = curtime.tm_hour % 12 minute = curtime.tm_min ap = "AM" if curtime.tm_hour < 12 else "PM" if hour == 0: hour = 12 fahr = int((temp * 9.0) / 5.0) + 32 draw.text((30, 170), f"{fahr}F {temp:.1f}C", font=dttf) draw.text((15, 90), f"{hour:02}:{minute:02} {ap}", font=ttf) date = localtime() # People outside the US will want to change this format draw.text( (20, 20), f"{date.tm_mon:02}/{date.tm_mday:02}/{date.tm_year}", font=dttf, ) disp.display(image) if minute % 15 == 2 and "chimeThread" in locals(): chimeThread.join(1.0) # noqa: F821 del chimeThread if minute % 15 == 0: chimeThread = Thread(target=play_chimes, args=(hour, minute)) chimeThread.start() sleep(2)
The following code prints out the current temperature. ##### import weather temperature = weather.get_temperature('Blacksburg, VA') if temperature < 65: print('Cold') else: print('Hot') ##### def on_run(code, output, properties): return True
# -*- coding: utf-8 -*- """ Created on Sat Feb 27 19:22:13 2016 @author: Romeo """ import weather temperature = weather.get_temperature("Miami, FL") print(temperature)
import weather ___ = 5 weather.get_temperature("Miami, FL") 32 print(___) fahrenheit = ___ print(___) ___ - ___ celsius = ___ fahrenheit 1.8 ___ / ___ fahrenheit celsius
def __init__(self, root): # Setup NSApi self.api = NSApi(config.NSAPI_USERNAME, config.NSAPI_PASSWORD) # Load stations self.stations = self.api.get_stations() print("Loaded {} stations".format(len(self.stations))) # Setup Tkinter self.root = root root.title("NS Miniproject") root.resizable(False, False) # Disable window resizing # Start frame setup frame_start = Frame(root, width=1024, height=768, background="#FED900") Label( frame_start, text="Welkom bij NS", foreground="#002A90", background="#FED900", font=("Tahoma", 48), ).place(x=307, y=143) Button( frame_start, text="Ik heb geen\nOV-chipkaart", foreground="white", background="#002A90", font=("Tahoma", 14), ).place(x=222, y=545) Button( frame_start, text="Ik wil naar\nhet buitenland", foreground="white", background="#002A90", font=("Tahoma", 14), ).place(x=442, y=545) Button( frame_start, text="Toon de\nvertrektijden", foreground="white", background="#002A90", font=("Tahoma", 14), command=self.show_main, ).place(x=662, y=545) # Weather Label( frame_start, text="Het is {}°C in {}".format( weather.get_temperature(self.location), self.location ), foreground="#002A90", background="#FED900", font=("Tahoma", 12), ).place(x=10, y=10) # Load image and keep reference so that the GC doesn't delete it img = ImageTk.PhotoImage(Image.open("src/assets/chipkaart.png")) frame_start._img_chipkaart = img # Draw image on canvas canvas = Canvas( frame_start, bg="#FED900", width=424, height=225, bd=0, highlightthickness=0 ) canvas.place(x=310, y=240) canvas.create_image(424 / 2, 225 / 2, image=img) frame_start.grid(row=0, column=0, sticky="nsew") # Main frame setup frame_main = Frame(root, width=1024, height=768) # Background canvas = Canvas(frame_main, width=1024, height=768, background="#002A90") canvas.pack() canvas.create_rectangle(0, 184, 1026, 688, fill="#FED900", outline="") # Header Label( frame_main, text="Vertrekstation", background="#002A90", foreground="white", font=("Tahoma", 28), ).place(x=20, y=20) Label( frame_main, text="Eindstation", background="#002A90", foreground="white", font=("Tahoma", 28), ).place(x=20, y=104) self.txtBeginStation = Entry(frame_main) self.txtBeginStation.place(x=308, y=35) self.txtBeginStation.insert(0, "Utrecht Centraal") self.txtEindStation = Entry(frame_main) self.txtEindStation.place(x=308, y=120) Button( frame_main, text="Zoek\ntreinen", background="#5F5FC4", foreground="white", font=("Tahoma", 28), command=self.update, ).place(x=827, y=20) # Main content - yellow Label( frame_main, text="Vertrek", background="#FED900", font=("Tahoma", 28) ).place(x=20, y=204) # Label( # frame_main, text="Aankomst", background="#FED900", font=("Tahoma", 28) # ).place(x=173, y=204) Label( frame_main, text="Bestemming", background="#FED900", font=("Tahoma", 28) ).place(x=300, y=204) Label( frame_main, text="Type trein", background="#FED900", font=("Tahoma", 28) ).place(x=700, y=204) # Entries row_height = 50 for i in range(self.stations_to_show): # Vetrek lbl = Label( frame_main, text="12:00", background="#FED900", font=("Tahoma", 28) ) lbl.place(x=20, y=271 + row_height * i) setattr(self, "lblVertrekTijd{}".format(i), lbl) # Aankomst # lbl = Label( # frame_main, text="13:00", background="#FED900", font=("Tahoma", 28) # ) # lbl.place(x=173, y=271 + row_height * i) # setattr(self, "lblAankomstTijd{}".format(i), lbl) # Bestemming lbl = Label( frame_main, text="Amsterdam Centraal", background="#FED900", font=("Tahoma", 28), ) lbl.place(x=300, y=271 + row_height * i) setattr(self, "lblBestemming{}".format(i), lbl) # Type trein lbl = Label( frame_main, text="InterCity", background="#FED900", font=("Tahoma", 28) ) lbl.place(x=700, y=271 + row_height * i) setattr(self, "lblType{}".format(i), lbl) # Footer Button( frame_main, text="Terug", background="#002A90", foreground="white", font=("Tahoma", 20), command=self.show_start, ).place(x=20, y=702) frame_main.grid(row=0, column=0, sticky="nsew") self.frame_start = frame_start self.frame_main = frame_main # Show start frame self.show_start() # Show times for default station Utrecht Centraal self.update()