#!/usr/bin/env python3 import json import requests import pytz from datetime import datetime, timedelta from pytz import timezone CURRENT_TZ = timezone('US/Pacific') # ^^^^^^^^ timezone to use for match start times LOGO_FILE = "/var/gemini-data/logos/gemhltv_matches" # ^^^^^^^ path to file containing the text to be displayed at the top of the # page with open(LOGO_FILE, "r") as logo: print("```\n" + logo.read() + "\n```") def print_matches(match_list): print("```") print("\n━━━━\n") print("```") for match in match_list: stars = int(match["stars"]) start_time = None; star_rating = "" title = match["event_name"] if stars != 0: title = title.split("-", 1) if len(title) > 1: title = "".join(title[1]).strip() else: title = "".join(title[0]).strip() star_rating += "(" for i in range(stars): star_rating += "★" star_rating += ")" else: stars = "" print("## {} {}".format(title, star_rating)) if match["rounds_won"] != []: # match is live if match["maps_won"] != []: # match has multiple maps print( "{} [{}({})]\nVS.\n{} [{}({})]".format( match["team_names"][0], match["rounds_won"][0], match["maps_won"][0], match["team_names"][1], match["rounds_won"][1], match["maps_won"][1], ) ) print("⏺️ LIVE") else: # match only has one map print( "{} [{}]\nVS.\n{} [{}]".format( match["team_names"][0], match["rounds_won"][0], match["team_names"][1], match["rounds_won"][1], ) ) print("⏺️ LIVE") elif match["maps_won"] != []: # match is over print( "{} [{}] - [{}] {}".format( match["team_names"][0], match["maps_won"][0], match["maps_won"][1], match["team_names"][1], ) ) print("FINAL") else: # match is upcoming, start time will always be an int here start_time = int(match["start_time"]) // 1000 # convert ms unix time to normal start_time = datetime.utcfromtimestamp(start_time) start_time = pytz.utc.localize(start_time).astimezone(CURRENT_TZ) start_time = start_time.strftime("%I:%M %p") print( "{}\nVS.\n{}".format( match["team_names"][0], match["team_names"][1], ) ) print("🕗 " + start_time) print("```") print("\n━━━━") print("```") print("") matches = json.loads(requests.get("https://illegaldrugs.net/skor").text) updated_on = matches.pop(0) live_matches = [ x for x in matches if x["start_time"] == "LIVE" ] upcoming_matches = [ x for x in matches if x["start_time"] != "LIVE" and x["start_time"] != "OVER" ] ended_matches = [ x for x in matches if x["start_time"] == "OVER" ] if len(live_matches) != 0: print("# LIVE") print_matches(live_matches) else: print("# LIVE\n") print("No live matches right now.\n") if len(upcoming_matches) != 0: print("# UPCOMING") print_matches(upcoming_matches) if len(ended_matches) != 0: print("# COMPLETED") print_matches(ended_matches) print("=> ?reload Refresh match list (only use this if a match that should be live is still in \"upcoming\")") print("\nPowered by sk0R")