def get_current_weather(): weath = "" try: owm = pyowm.OWM(KEYS.get_weather_key()) observation = owm.weather_at_place('Meadville, PA, US') w = observation.get_weather() weath += '\n' + w.get_status() + '\nTemperature: ' + str( int(w.get_temperature('fahrenheit') ['temp'])) + '°F\nHumidity: ' + str(w.get_humidity()) + '%' return weath except BaseException: return "No key entered in configuration file, weather cannot be given"
def __init__(self, authors, title, urls): self.authors = authors self.title = title self.urls = urls # hackathon hack! if not len(authors): self.authors = [""] if not len(urls): self.urls = ["NOT_APPLICABLE_90125738943705"] if (authors[0], title) in social_cache: self.twitter_results = social_cache[(authors[0], title, urls[0])]['twitter'] return social_cache[(self.authors[0], self.title, self.urls[0])] = {} (APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) = KEYS.keys() self.tw = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) self.twitter_results = "" self.reddit_results = ""
# try to clear chart try: # clear chart AlphaVantage.ClearChart() return # if an error occurs except: # print error message print("An error occured in DiscordBot.ClearStockChart") return # delete image file def DeleteImage(imagePath): # try to delete file try: # delete file os.remove(imagePath) return # if an error occurs except: # print error message print("An error occured in DiscordBot.DeleteImage") return # get login key loginKey = KEYS.GetDiscordLoginToken() # run bot using login token client.run(loginKey)
import webbrowser import time Log.log_debug(str(datetime.datetime.now()) + " >> System Started") try: from groupy import Client from groupy import session from groupy.api import bots from groupy.api import messages from groupy.api.attachments import Mentions from groupy.api import groups config_file = Path("./config.ini") if not config_file.is_file(): KEYS.new_config() while KEYS.get_groupme_key() == "": print( "Please enter a GroupMe API Key in config.ini and then press enter to continue" ) time.sleep(1) webbrowser.open('./config.ini') input() except BaseException: print( "Required packages not installed, please run 'pip3 install -r requirements.txt'" ) quit() client = Client.from_token(KEYS.get_groupme_key()) # creates new session (uses api key from groupme), needed for all objects
import datetime import json import random import KEYS import requests # get api key apiKey = KEYS.GetNASAKey() # get nasa picture of the day def PictureOfDay(pictureDate): # api url url = 'https://api.nasa.gov/planetary/apod' # create header headers = {'Accept': 'application/json'} # if no date is given if pictureDate is None: # create body body = {'api_key': apiKey} # api call to get image information r = requests.request(method="GET", url=url, headers=headers, params=body) # if image is a youtube video
import json import KEYS import requests # get api key apiKey = KEYS.GetDogKey() # API key authentication headers = {'X-API-KEY': apiKey} # gets dog image from API def CreateDogImage(): # API search url url = 'https://api.thedogapi.com/v1/images/search' # API call parameters body = {"size": "large", "limit": 1, "mime_types": "gif"} # request an image from API r = requests.request(method="GET", url=url, headers=headers, params=body) # get response content as text dataString = r.text # remove open and closing bracket dataString = dataString[1:-1] # convert data from string to dictionary dataDictionary = json.loads(dataString) # get url from dataDictionary imageUrl = dataDictionary['url']
import json import random import KEYS import requests # get contact info contactInfo = KEYS.GetJokeContactInfo() # request header headers = {'Accept': 'application/json', 'User-Agent': contactInfo} # get a random dad joke def GetDadJoke(): # api request for joke r = requests.get('https://icanhazdadjoke.com/', headers=headers) # convert response text to dictionary data = json.loads(r.text) # return joke from dictionary return '> ' + data['joke'] # search dad jokes by search term def SearchDadJoke(searchValue): # set search value to the passed parameter body = {'term': searchValue} # api request for joke based on search term r = requests.get('https://icanhazdadjoke.com/search',
import json import KEYS import requests # get api key apiKey = KEYS.GetCatKey() # API key authentication headers = {'X-API-KEY': apiKey} # gets cat image from API def CreateCatImage(): # API search url url = 'https://api.thecatapi.com/v1/images/search' # API call parameters body = {"size": "large", "limit": 1, "mime_types": "gif"} # request an image from API r = requests.request(method="GET", url=url, headers=headers, params=body) # get response content as text dataString = r.text # remove open and closing bracket dataString = dataString[1:-1] # convert data from string to dictionary dataDictionary = json.loads(dataString) # get url from dataDictionary imageUrl = dataDictionary['url']
import json import time import nltk from nltk.corpus import stopwords from operator import itemgetter from collections import Counter from string import punctuation from mymodels import * from analyze_polarity import learn_tweet_polarity from dateutil.relativedelta import relativedelta import datetime #import requests.packages.urllib3 #requests.packages.urllib3.disable_warnings() consumer_key = KEYS.get_consumer_key() consumer_secret = KEYS.get_consumer_secret() access_token = KEYS.get_access_token() access_token_secret = KEYS.get_access_token_secret() # For now, only takes into account central time. def convertUTC(time_tuple): days = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"] day_index = days.index(str(time_tuple[0])) hour = int(time_tuple[1]) # Offset for Dallas time hour -= 5
import os.path import sys import KEYS import matplotlib.pyplot as plt import pandas import requests from alpha_vantage.timeseries import TimeSeries # alpha vantage api key apiKey = KEYS.GetAlphaVantageKey() # show all rows/columns from DataFrame pandas.set_option('display.max_rows', None) pandas.set_option('display.max_columns', None) # function for getting stock data def GetStock(stockName): # initiate alpha vantage timeseries api ts = TimeSeries(key=apiKey, output_format='pandas') # try to get stock data try: # get stock data data, metadata = ts.get_intraday(symbol=stockName, interval="60min", outputsize="full") # return stock data return data, metadata # if a ValueError occurs except ValueError as error:
import json import KEYS import requests # get contact info apiKey = KEYS.GetOmbdKey() # create url url = 'http://www.omdbapi.com/' + '?apikey=' + str(apiKey) # create header headers = {'Accept': 'application/json'} # get information of a movie/series title def GetInformation(title): # make title a string title = str(title) # add title to parameters body = {'t': title, 'plot': 'short'} # request information from api r = requests.get(url, headers=headers, params=body) # if no movies/shows were found if r.text.__contains__('Movie not found!'): # return no movies/shows message return "> Sorry, there were no movies/shows for that term!" # convert string to dictionary data = json.loads(r.text)