def render_loop(glyphs, font): last_mta_fetch = 0 last_weather_fetch = 0 matrix = init() times_by_line = {} current = {} forecast = [] status = {} while True: now = time.time() if now - last_mta_fetch > 60: try: status = mta.status() times_by_line.update( mta.times_from_subwaytime(SUBWAYTIME_STOPS)) last_mta_fetch = now err = None except Exception, ex: err = str(ex) if now - last_weather_fetch > 300: try: current = weather.current() forecast = weather.forecast() last_weather_fetch = now except Exception, ex: err = str(ex)
def forecastseach(message): cid = message.chat.id bot.send_chat_action(cid, 'typing') try: latlon = weather.getLatLon(weather.getJson(message.text)); if latlon: bot.send_location(cid, latlon[0], latlon[1]) bot.send_message(cid,weather.forecast(weather.getJson(message.text.replace(" ", "_")))) except Exception as e: bot.reply_to(message, CRYINGFACE + ' oooops je suis trop fatigue pour y arriver..' + str(e))
def selection(what_i_said): find_truth = pre_selection(what_i_said, slct) if not find_truth: talking('How can I help you sir') menus.menu_choice() what_i_said = listening() what_i_said = what_i_said.replace('what\'s','what is') find_truth = pre_selection(what_i_said, slct) print find_truth while True: if (find_truth == [0, 1]) or (find_truth == [15]): games.play_hi_low() break elif find_truth == [2]: break elif (find_truth == [3, 4, 16, 17]) or (find_truth == [4, 9, 16, 17]) or (find_truth == [3, 4, 9, 16, 17]) \ or (find_truth == [3, 4]) or (find_truth == [4, 9]) or (find_truth == [3, 4, 9]): weather.current_weather() break elif (find_truth == [4, 5]) or (find_truth == [5]) or (find_truth == [4, 5, 16, 17]) or \ (find_truth == [4, 16, 17]): weather.forecast() break elif find_truth == [6, 7, 8]: games.RPSGame() break elif find_truth == [10]: games.tell_joke() break elif (find_truth == [11, 12]) or (find_truth == [11, 13]) or (find_truth == [11, 14]): todo_action.todo(find_truth) break elif (find_truth == [16, 17]) or (find_truth == [17, 18]) or (find_truth == [17, 19]) or \ (find_truth == [17, 20]) or (find_truth == [17, 21]) or (find_truth == [16, 22]) or \ (find_truth == [22, 18]) or (find_truth == [22, 19]) or (find_truth == [22, 20]) or \ (find_truth == [22, 21]): knowledge.wolfram_alpha(what_i_said) break else: decide(what_i_said) break
def logdata(): print('ran') while True: data = [] tm = time.localtime() if tm.tm_hour % 6 == 0 & tm.tm_sec == 0: data.append( [tm, int(weather.forecast().today[f'{tm.tm_hour}:00'].temp)]) with open('data.dat', 'w') as f: f.write(str(data))
def main(): past = [] forecast = [] with open("setting.txt") as f: for l in [row for row in csv.reader(f)]: past.append(weather.AmeDAS(l[1], l[0])) forecast.append(weather.forecast(past[len(past) - 1].all[1])) f.close() with open("logtime.txt", mode='w') as f: f.write( datetime.now(timezone(timedelta(hours=+9), 'JST')).strftime("%Y/%m/%d %H:%M:%S"))
async def update_forecast_cache(city_id): city = database.get_city(city_id) if (city is None): raise HTTPException( status_code=HTTP_404_NOT_FOUND, detail="Não foi possível encontrar a cidade com o id {}".format( city_id)) city_api_id = city['api_id'] now = datetime.utcnow() last = datetime.fromisoformat(city['timestamp']) if (now - last).days >= 1: city['forecast'] = weather.forecast(city_api_id) cities.write_back(city) return database.get_city(city_id)
def weather_speaker(): forcast = weather.forecast() engine.say(forcast) engine.runAndWait()
from distances import parks_list, find_parks, get_cords from weather import forecast parks = [] parks = parks_list('national_parks.csv') user_cords = get_cords() park_distances = find_parks(user_cords, parks) for park, data in park_distances.items(): weather_forecast = forecast(data[1], data[2]) sky = weather_forecast['weather'][0]['description'] high = str(round(weather_forecast['main']['temp_max'])) + '°F' low = str(round(weather_forecast['main']['temp_min'])) + '°F' print('\n' + park, 'is', data[0], 'miles away from you.') print('Outlook:', sky) print('High:', high) print('Low:', low)
import praw import pdb import re import os import weather reddit = praw.Reddit('bot1') if not os.path.isfile("posts_replied_to.txt"): posts_replied_to = [] else: with open("posts_replied_to.txt", "r") as f: posts_replied_to = f.read() posts_replied_to = posts_replied_to.split("\n") posts_replied_to = list(filter(None, posts_replied_to)) subreddit = reddit.subreddit('pythonforengineers') for submission in subreddit.hot(limit=5): if submission.id not in posts_replied_to: if re.search("i love python", submission.title, re.IGNORECASE): submission.reply(weather.forecast()) print("Bot replying to : ", submission.title) posts_replied_to.append(submission.id) with open("posts_replied_to.txt", "w") as f: for post_id in posts_replied_to: f.write(post_id + "\n")
def forecast(): return jsonify(weather.forecast(app.config))
def forecast_wrapper(message): Weather.forecast(message)
import praw import weather reddit = praw.Reddit('bot1') print(weather.forecast()) subreddit = reddit.subreddit("pythonforengineers") for submission in subreddit.hot(limit=5): print("Title: ", submission.title) print("Text: ", submission.selftext) print("Score: ", submission.score) print("---------------------------------\n")