Compare commits

...

2 Commits

Author SHA1 Message Date
publicmatt 9692e06cca Auto-updating git readme 2023-12-18 18:03:28 -08:00
publicmatt eb32384a4e add python for updating chat bubble. 2023-12-18 18:03:22 -08:00
6 changed files with 509 additions and 10 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.env
.venv

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
PYTHON=.venv/bin/python
.PHONY: build install
install: requirements.txt
$(PYTHON) -m pip install -r $^
build: build-svg.py template.svg
$(PYTHON) $<
git add '*.svg' && \
GIT_AUTHOR_NAME='publicmatt' GIT_AUTHOR_EMAIL='git@publicmatt.com' \
GIT_COMMITTER_NAME='publicmatt' GIT_COMMITTER_EMAIL='git@publicmatt.com' \
git commit -m "Auto-updating git readme"
git push publicmatt
git push github

96
build-svg.py Normal file
View File

@ -0,0 +1,96 @@
import os
import requests
import pendulum
import json
from dotenv import load_dotenv
import sys
from pathlib import Path
# load env files
load_dotenv()
# part of current dir
app_path = Path(__file__).parent
# Environment variable for API key
WEATHER_API_KEY = os.getenv("WEATHER_API_KEY")
WEATHER_DOMAIN = "http://dataservice.accuweather.com"
# emojis that accuweather uses
emojis = {
1: "☀️",
2: "☀️",
3: "🌤",
4: "🌤",
5: "🌤",
6: "🌥",
7: "☁️",
8: "☁️",
11: "🌫",
12: "🌧",
13: "🌦",
14: "🌦",
15: "",
16: "",
17: "🌦",
18: "🌧",
19: "🌨",
20: "🌨",
21: "🌨",
22: "❄️",
23: "❄️",
24: "🌧",
25: "🌧",
26: "🌧",
29: "🌧",
30: "🥵",
31: "🥶",
32: "💨",
}
dayBubbleWidths = {
"Monday": 235,
"Tuesday": 235,
"Wednesday": 260,
"Thursday": 245,
"Friday": 220,
"Saturday": 245,
"Sunday": 230,
}
# Time since graduating
today = pendulum.now()
todayDay = today.format("dddd")
psTime = pendulum.instance(today).diff_for_humans(
pendulum.datetime(2023, 12, 14), absolute=True
)
# Today's weather
locationKey = "331416" # Bellingham
url = f"forecasts/v1/daily/1day/{locationKey}?apikey={WEATHER_API_KEY}"
try:
response = requests.get(f"{WEATHER_DOMAIN}/{url}")
response.raise_for_status()
json_data = response.json()
degF = round(json_data["DailyForecasts"][0]["Temperature"]["Maximum"]["Value"])
degC = round((degF - 32) * 5 / 9)
icon = json_data["DailyForecasts"][0]["Day"]["Icon"]
with open(app_path / "template.svg", "r", encoding="utf-8") as file:
data = file.read()
data = data.replace("{degF}", str(degF))
data = data.replace("{degC}", str(degC))
data = data.replace("{weatherEmoji}", emojis[icon])
data = data.replace("{psTime}", psTime)
data = data.replace("{todayDay}", todayDay)
data = data.replace("{dayBubbleWidth}", str(dayBubbleWidths[todayDay]))
with open(app_path / "chat.svg", "w", encoding="utf-8") as file:
file.write(data)
except requests.exceptions.RequestException as err:
print(err, file=sys.stderr)

View File

@ -248,10 +248,10 @@
</g>
<!-- Hi, I'm Jason -->
<!-- Hi, I'm Matt -->
<g transform="translate(10, 0)" class="msg-1 bubble">
<rect width="133" height="42" rx="18.0355" />
<text x="15" y="27">Hi, I'm Jason</text>
<text x="15" y="27">Hi, I'm Matt</text>
</g>
<!-- typing 2 -->
@ -272,11 +272,11 @@
</g>
<!-- From Columbus... -->
<!-- From Bellingam... -->
<g transform="translate(10, 48)" class="msg-2">
<rect width="439" height="66.1302" rx="18.0355" class="bubble" />
<text x="15" y="27">I live in Columbus, Ohio where its supposed to be</text>
<text x="15" y="50">49° F (9° C) and <tspan class="emoji">🌧</tspan> today.</text>
<text x="15" y="27">I live in Bellingham, Washington where its supposed to be</text>
<text x="15" y="50">46° F (8° C) and <tspan class="emoji">🌦</tspan> today.</text>
</g>
<!-- typing 3 -->
@ -300,8 +300,8 @@
<!-- Work ... -->
<g transform="translate(10, 120)" class="msg-3">
<rect width="439" height="66.1302" rx="18.0355" class="bubble" />
<text x="15" y="27">Im a product designer. I used to work at GitHub,</text>
<text x="15" y="50">but Ive been at PlanetScale for almost 3 years now.</text>
<text x="15" y="27">I write software. I work with web tech, data and machine learning,</text>
<text x="15" y="50">and graduated from Western Washington University with a MS in Computer Science 5 days ago.</text>
</g>
<!-- typing 4 -->
@ -322,12 +322,12 @@
</g>
<!-- Twitter -->
<!-- Contact -->
<g transform="translate(10, 192)" class="msg-4">
<rect width="513" height="42" rx="18.0355" class="bubble" />
<text x="15" y="27">
You can find me on Twitter at
<a xlink:href="https://twitter.com/jasonlong">https://twitter.com/jasonlong</a>
You can find me online at
<a xlink:href="https://www.publicmatt.com">https://www.publicmatt.com/</a>
</text>
</g>

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 134 KiB

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
requests
pendulum
quantiphy
python-dotenv

381
template.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 134 KiB