Skip to content

Instantly share code, notes, and snippets.

View erichare's full-sized avatar
🏠
Working from home

Eric Hare erichare

🏠
Working from home
View GitHub Profile
@erichare
erichare / noaa_ui.py
Created August 3, 2022 22:25
UI code for the NOAA daisi
st.title("NOAA Weather API Interface")
st.write("This Daisi, powered by the `noaa-sdk` Python package, allows for an interaction with the NOAA API for pulling weather forecast data.")
with st.sidebar:
cc = st.text_input("Country Code", value="US")
pc = st.text_input("Postal Code", value="77001")
wx_keys, wx_dat = available_wx_data(cc, pc)
vars = st.multiselect("Weather Metrics", options=wx_keys, default=["temperature", "dewpoint"])
@erichare
erichare / noaa_functions.py
Created August 3, 2022 22:17
Functions to interface with the noaa-sdk package
def available_wx_data(country_code, postal_code):
res = n.get_observations(postal_code, country_code)
return sorted(list(list(res)[0].keys())), res
def forecast(country_code, postal_code, vars, dat=None):
if not dat:
dat = n.get_forecasts(postal_code, country_code, type='forecastGridData')
return {k:v for k, v in dat.items() if k in vars}
@erichare
erichare / twitter_sentiment_gs_daisi.py
Last active July 20, 2022 13:25
Extract Twitter Sentiment and store in Google Sheets with Daisi
import pydaisi as pyd
twitter_sentiment = pyd.Daisi("erichare/Twitter Sentiment")
google_spreadsheets = pyd.Daisi("erichare/Google Spreadsheets")
result = twitter_sentiment.get_twitter_sentiment("Pizza", count=10, tweets=None)
with open("service-account-file.json", "r") as my_f:
print(google_spreadsheets.store_in_gs(result, "[email protected]", my_f.read(), title="Pizza Dat", append = True).value)
@erichare
erichare / daisi_spreadsheets.py
Created July 19, 2022 21:02
Interfacing with a Daisi to produce a Google Spreadsheet
import pydaisi as pyd
import pandas as pd
google_spreadsheets = pyd.Daisi("erichare/Google Spreadsheets")
df = pd.read_csv("https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv")
email = "<your_email_here>"
with open("service_account.json") as my_f:
service_account = my_f.read()
@erichare
erichare / twitter_sentiment_sample.py
Created July 14, 2022 20:16
Sample code for running Twitter Sentiment
import pydaisi as pyd
twitter_sentiment = pyd.Daisi("erichare/Twitter Sentiment")
result = twitter_sentiment.get_twitter_sentiment("Python", count=50).value
result
@erichare
erichare / twitter_daisi_code.py
Created July 14, 2022 15:39
Daisi code for the Twitter Search Daisi
import tweepy
import pandas as pd
# Add Twitter API key and secret
consumer_key = "<redacted>"
consumer_secret = "<redacted>"
# Handling authentication with Twitter
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
@erichare
erichare / sentiment_analysis_daisicode.py
Created July 14, 2022 15:38
Sample of the code of the sentiment analysis Daisi
import tensorflow as tf
from transformers import pipeline
sentiment_task = pipeline("sentiment-analysis", model="sentiment-roberta-large-english", tokenizer="sentiment-roberta-large-english")
def get_sentiment(text):
'''
Use a Sentiment Detection model on the given text
...
@erichare
erichare / twitter_sentiment.py
Created July 14, 2022 14:29
Pull Twitter data and then compute the sentiment
import pydaisi as pyd
tw_daisi = pyd.Daisi("erichare/Twitter Search")
sa_daisi = pyd.Daisi("erichare/Sentiment Analysis")
result = tw_daisi.fetch_tweets("Pepperoni Pizza", count=10).value
sentiment = sa_daisi.get_sentiment([x for x in result["text"].tolist()]).value
result["label"] = [x["label"] for x in sentiment]
result["score"] = [x["score"] for x in sentiment]
@erichare
erichare / sentiment_analysis.py
Created July 14, 2022 14:22
Interface with the Daisi for Sentiment Analysis
import pydaisi as pyd
sentiment_analysis = pyd.Daisi("erichare/Sentiment Analysis")
sentiment_analysis.get_sentiment("I am so happy").value
sentiment_analysis.get_sentiment(["I am so happy", "Actually, I'm not sure", "I'm pretty upset"]).value
@erichare
erichare / twitter_search.py
Last active July 14, 2022 14:18
Interface with the Twitter Search Daisi
import pydaisi as pyd
twitter_search = pyd.Daisi("erichare/Twitter Search")
tweets = twitter_search.fetch_tweets(query="Pepperoni Pizza", count=10).value
tweets