def get_btc_eth(C_3_URL, C_4_URL, LOCAL_CUR, color): """Retrieve Bitcoin and Etherium exchange rates.""" C_URL_3 = C_3_URL + str(LOCAL_CUR) + '.json' C_URL_4 = C_4_URL + str(LOCAL_CUR).lower() # print(C_URL_3) # print(C_URL_4) bitcoin_exchange = "" eth_exchange = "" response_c_3 = d_f.url_content(C_URL_3, 'currency_3', {}, color) response_c_4 = d_f.url_content(C_URL_4, 'currency_4', {}, color) if response_c_3 and response_c_4: # print('Connection to Crypto successful.') c_3_data = response_c_3.json() c_4_data = response_c_4.json() bitcoin_exchange = "1 BTC: " + \ str("{:.2f}".format(float(c_3_data['bpi'][str(LOCAL_CUR)]['rate_float']))) eth_exchange = "1 ETH: " + \ str("{:.2f}".format(float(c_4_data['ethereum'][str(LOCAL_CUR).lower()]))) return bitcoin_exchange, eth_exchange
def get_currency(C_1_URL, C_1_API, LOCAL_CUR, C_CHECK, color): """Retrieve currency conversion rates.""" C_URL_1 = str(C_1_URL) + '/api/v7/convert?q=' + \ str(C_CHECK) + '_' + str(LOCAL_CUR) + '&compact=ultra&apiKey=' + str(C_1_API) # print(C_URL_1) cur_exch = '' response_c_1 = d_f.url_content(C_URL_1, 'currency_1', {}, color) if response_c_1: # print('Connection to Currencyconverterapi successful.') c_1_data = response_c_1.json() cur_exch = "{:.4f}".format(float(c_1_data[str(C_CHECK) + '_'+str(LOCAL_CUR)])) return cur_exch
def get_geo(G_URL, G_API, color): """Get geolocation data.""" g_data = [] GEO_URL = str(G_URL) + '?api-key=' + str(G_API) # print(GEO_URL) geo_data = [] response_g = d_f.url_content(GEO_URL, 'geolocation', {}, color) if response_g: g_data = response_g.json() geo_data.append(g_data["city"]) geo_data.append(g_data["region_code"]) geo_data.append(g_data["country_name"]) geo_data.append(g_data["latitude"]) geo_data.append(g_data["longitude"]) geo_data.append(g_data["currency"]["code"]) geo_data.append(g_data["currency"]["name"]) geo_data.append(g_data["country_code"]) return geo_data
def get_stock_weekend(ST_URL, ST_API, ST_C, st_base, LOCAL_CUR, color): """Request most recent? stock values.""" URL_ST = ST_URL + ST_C + "/prev?apiKey=" + str(ST_API) # print(URL_ST) stocks = [] response_st = d_f.url_content(str(URL_ST), 'currency_stock_weekend', {}, color) if response_st: # print('Connection to Stock successful.') st_data = response_st.json() st_open = st_data["results"][0]["o"] st_symbol = st_data["results"][0]["T"] st_close = st_data["results"][0]["c"] stocks.append("-" + st_symbol + ":") stocks.append( "O: " + str("{:.2f}".format((float(st_open)*float(st_base))))) stocks.append( "C: " + str("{:.2f}".format((float(st_close)*float(st_base))))) return stocks
def get_stock_week(ST_URL, ST_API, ST_C, st_base, LOCAL_CUR, color): """Currently unused - see get_stock_weekend which is used unconditionally.""" st_date = get_year() URL_ST = ST_URL + ST_C + "/" + str(st_date) + "?apiKey=" + str(ST_API) # print(URL_ST) stocks = [] response_st = d_f.url_content(str(URL_ST), 'currency_stock_week', {}, color) if response_st: # print('Connection to Stock successful.') st_data = response_st.json() st_open = st_data["open"] st_symbol = st_data["symbol"] st_close = st_data["close"] stocks.append("-" + st_symbol + ":") stocks.append( "O: " + str("{:.2f}".format((float(st_open)*float(st_base))))) stocks.append( "C: " + str("{:.2f}".format((float(st_close)*float(st_base))))) return stocks
def get_movies(M_URL_1, color): """Pull down movie listings.""" #Following block replaced by "response_g = .../if response_g:" lines #error_connect = True #while error_connect is True: # try: # # HTTP request # # print('Attempting to connect to OWM.') # response_c_1 = requests.get(str(C_URL_1)) # error_connect = None # except: # # Call function to display connection error # print('Connection error.') # # error_connect = None # # error = True # # d_f.display_error(' MOVIE CONNECTION', color) # # break # # delete the comment below # # #error = None #while error is None: # # Check status of code request # if response_c_1.status_code != 200: # # Call function to display HTTP error # break # # d_f.display_error('HTTP CURRENCY', color) # else: movie_data = [] response_m = d_f.url_content(M_URL_1, 'movies', {}, color) if response_m: # print('Connection to Movies successful.') m_1_data = response_m.json() #FIXME return movie_data
def get_news(NEWS_URL, NEWS_API, NEWS_SOURCES, news_country, news_num, color): """Retrieve news.""" if news_num == 0: news_URL = str(NEWS_URL) + "country=" + str( news_country).lower() + "&apiKey=" + str(NEWS_API) elif news_num == 1: news_URL = str(NEWS_URL) + "sources=" + str( NEWS_SOURCES) + "&apiKey=" + str(NEWS_API) # print(news_URL) news_items = [] response_n = d_f.url_content(news_URL, 'news', {}, color) if response_n: # print('Connection to News successful.') n_data = response_n.json() # print(n_data) for x in range(0, 5): chk_str = int(len(str(n_data["articles"][x]["title"]))) chk_str_1 = chk_str # print(x) #print("before: " + str(chk_str)) # 43 check = False if chk_str > 48: chk_str = 48 else: # chk_str = chk_str #Does no action check = True #print("after: " + str(chk_str)) while check is False: if str(n_data["articles"][x]["title"])[chk_str] != " ": chk_str = chk_str - 1 #print("space_false: " + str(chk_str)) check = False else: # chk_str = chk_str #Does no action #print("space_true: " + str(chk_str)) check = True if chk_str_1 >= 48: news_items.append( str(x + 1) + "- " + str(n_data["articles"][x]["title"])[0:chk_str] + " ") if chk_str_1 > 92: news_items.append( str(n_data["articles"][x]["title"])[chk_str + 1:91] + " ") else: news_items.append( str(n_data["articles"][x]["title"])[chk_str + 1:chk_str_1] + " ") else: news_items.append( str(x + 1) + "- " + str(n_data["articles"][x]["title"])[0:chk_str] + " ") # print(news_items[x]) return news_items
def get_weather(WEATHER_URL, LATITUDE, LONGITUDE, UNITS, W_API_KEY, color): """Retrieve the weather from openweathermap.""" W_URL = WEATHER_URL + 'lat=' + LATITUDE + '&lon=' + \ LONGITUDE + '&units=' + UNITS + '&appid=' + W_API_KEY + \ '&exclude=hourly,minutely,alerts' # print(W_URL) weather_data = [] response_w = d_f.url_content(W_URL, 'weather', {}, color) if response_w: w_data = response_w.json() current = w_data['current'] utc_time = current['dt'] day_name = d_f.get_time(utc_time) temp_current = current['temp'] #feels_like = current['feels_like'] #humidity = current['humidity'] #wind = current['wind_speed'] weather = current['weather'] report = weather[0]['description'] icon_code = weather[0]['icon'] # icon_URL = 'http://openweathermap.org/img/wn/'+ icon_code +'@4x.png' # get daily dict block daily = w_data['daily'] #daily_precip_float = daily[0]['pop'] #daily_precip_percent = daily_precip_float * 100 daily_temp = daily[0]['temp'] temp_max = daily_temp['max'] temp_min = daily_temp['min'] if UNITS == "metric": unit = "C" elif UNITS == "imperial": unit = "F" weather_data.append('Today is ' + str(day_name)) weather_data.append( str(format(temp_current, '.0f')) + u'\N{DEGREE SIGN}' + str(unit)) # weather_data.append('Feels Like: ' + str(feels_like)) # weather_data.append('Humidity: ' + str(humidity)) # weather_data.append('Wind Speed: '+str(wind)) if str(report.title()) == 'heavy intensity rain': weather_data.append('heavy rain') else: weather_data.append(str(report.title())) weather_data.append( str(format(temp_max, '.0f')) + u'\N{DEGREE SIGN}' + str(unit) + ' / ' + str(format(temp_min, '.0f')) + u'\N{DEGREE SIGN}' + str(unit)) # weather_data.append('Probabilty of Precipitation: ' + # str(daily_precip_percent) + '%') weather_data.append(str(icon_code)) weather_data.append("Forecast") for x in range(0, 5): weather_data.append(str(d_f.get_time(daily[x]['dt']))) weather_data.append( str(format(daily[x]['temp']['max'], '.0f')) + u'\N{DEGREE SIGN}' + str(unit) + ' / ' + str(format(daily[x]['temp']['min'], '.0f')) + u'\N{DEGREE SIGN}' + str(unit)) weather_data.append(daily[x]['weather'][0]['icon']) if daily[x]['weather'][0]['description'] == 'heavy intensity rain': weather_data.append('heavy rain') else: weather_data.append(daily[x]['weather'][0]['description']) return weather_data