So, I was wondering if I still needed to use an Ordered Dictionary for this.
import requests
import time
import collections
import threading
class LiveChecker:
"""Editable YT streamer checker. Meant to be used with a discord bot. Edit the module directly to change which streamers to track."""
def __init__(self):
self.headers = {'Accept-Encoding' : 'identity'}
self.initial = { 'Gura':'https://www.youtube.com/channel/UCoSrY_IQQVpmIRZ9Xf-y93g', #name as key, link as value
'Calli':'https://www.youtube.com/channel/UCL_qhgtOy0dy1Agp8vkySQg',
'Kiara':'https://www.youtube.com/channel/UCHsx4Hqa-1ORjQTh9TYDhww',
'Ina':'https://www.youtube.com/channel/UCMwGHR0BTZuLsmjY_NT5Pwg',
'Ame':'https://www.youtube.com/channel/UCyl1z3jo3XHR1riLFKG5UAg',
'Noel':'https://www.youtube.com/channel/UCdyqAaZDKHXg4Ahi7VENThQ',
'Pekora':'https://www.youtube.com/channel/UC1DCedRgGHBdm81E1llLhOQ',
'Suisei':'https://www.youtube.com/channel/UC5CwaMl1eIgY8h02uZw7u8A',
'Okayu':'https://www.youtube.com/channel/UCvaTdHTWBGv3MKj3KVqJVCw',
'Korone':'https://www.youtube.com/channel/UChAnqc_AY5_I3Px5dig3X1Q',
'Flare':'https://www.youtube.com/channel/UCvInZx9h3jC2JzsIzoOebWg',
'Ollie':'https://www.youtube.com/channel/UCYz_5n-uDuChHtLo7My1HnQ',
'Moona':'https://www.youtube.com/channel/UCP0BspO_AMEe3aQqqpo89Dg',
'Rushia':'https://www.youtube.com/channel/UCl_gCybOJRIgOXw6Qb4qJzQ',
'Coco':'https://www.youtube.com/channel/UCS9uQI-jC3DE0L4IpXyvr6w',
'Aqua':'https://www.youtube.com/channel/UC1opHUrw8rvnsadT-iGp7Cg',
'Subaru':'https://www.youtube.com/channel/UCvzGlP9oQwU--Y0r9id_jnA'}
self.OD = collections.OrderedDict(sorted(self.initial.items())) # used to keep the dict consistent (and sorted through
# alphabetical order)
def checker(self, name, link):
live = requests.get(link, headers = self.headers)
if '{"accessibilityData":{"label":"LIVE"}}},"style":"LIVE","icon":{"iconType":"LIVE"}' in live.text:
states = "**LIVE**"
else:
states = "*Offline*"
self.toAnswer += [f"{name}: {states}"]
def gettp(self):
self.toAnswer = []
threads = []
for i in self.OD.keys():
process = threading.Thread(target = self.checker, args = [i, self.OD[i]])
process.start()
threads.append(process)
for process in threads:
process.join()
print(f"STREAMER STATES: Updated ({time.strftime('%H:%M:%S', time.localtime())})")
def getRes(self):
return ('\n'.join(sorted(self.toAnswer)))
if __name__ == '__main__': # Debugging
from os import system
system("title yts Debug")
wl = LiveChecker()
while True:
wl.gettp()
print(wl.getRes())
time.sleep(3)
# forgive my weeb!
I read somewhere that dictionaries weren't ordered, so I thought making it ordered would make it, at the very least, consistent. However, I read a more recent thing that said that dictionaries were now inherently ordered by entry, just like what an ordereddict is.
So I was wondering, in the example above, if it was still necessary to keep using an Ordered Dict.