kopia lustrzana https://codeberg.org/edent/Mastodon_Tools
50 wiersze
1.5 KiB
Python
Executable File
50 wiersze
1.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
from mastodon import Mastodon
|
|
import json
|
|
import requests
|
|
import config
|
|
|
|
# Set up access
|
|
mastodon = Mastodon( api_base_url=config.instance, access_token=config.write_access_token )
|
|
|
|
# Untappd API
|
|
untappd_api_url = 'https://api.untappd.com/v4/user/checkins/edent?client_id=' + config.untappd_client_id + '&client_secret='+ config.untappd_client_secret
|
|
|
|
r = requests.get(untappd_api_url)
|
|
|
|
untappd_data = r.json()
|
|
|
|
# Latest checkin object
|
|
checkin = untappd_data["response"]["checkins"]["items"][0]
|
|
untappd_id = checkin["checkin_id"]
|
|
|
|
# Was this ID the last one we saw?
|
|
check_file = open("untappd_last", "w+")
|
|
last_id = check_file.read()
|
|
|
|
if (last_id != str(untappd_id) ) :
|
|
check_file.write( str(untappd_id) )
|
|
check_file.close()
|
|
# Start creating the message
|
|
message = ""
|
|
|
|
if "checkin_comment" in checkin :
|
|
message += checkin["checkin_comment"]
|
|
|
|
if "beer" in checkin :
|
|
message += "\nDrinking: " + checkin["beer"]["beer_name"]
|
|
|
|
if "brewery" in checkin :
|
|
message += "\nBy: " + checkin["brewery"]["brewery_name"]
|
|
|
|
if "venue_name" in checkin :
|
|
message += "\nIn: " + checkin["venue"]["venue_name"]
|
|
# Scores etc
|
|
untappd_checkin_url = "https://untappd.com/user/edent/checkin/" + str(untappd_id)
|
|
untappd_rating = checkin["rating_score"]
|
|
untappd_score = "🍺" * int(untappd_rating)
|
|
|
|
message += "\n" + untappd_score + "\n" + untappd_checkin_url + "\n" + "#untappd"
|
|
# Post to Mastodon. Use idempotency just in case something went wrong
|
|
mastodon.status_post(status = message, idempotency_key = str(untappd_id))
|