Skip to content

Instantly share code, notes, and snippets.

@DavidLutton
Created May 29, 2019 19:30
Show Gist options
  • Save DavidLutton/1490a8b3d1c76d8f7a96eb70ff4d5d71 to your computer and use it in GitHub Desktop.
Save DavidLutton/1490a8b3d1c76d8f7a96eb70ff4d5d71 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from pathlib import Path
from pprint import pprint
from requests_html import HTMLSession
import toml
import schedule
from time import sleep
def get_recycling():
uri = 'https://x.secure.force.com/WasteServices/View?id='
session = HTMLSession()
r = session.get(uri)
txt = r.html.find('table')[0].text
wrap = dict(zip(txt.split('\n')[0::4][1:], map(lambda x: x.split(' ')[1], txt.split('\n')[2::4][1:])))
wrap['Food Bin'] = wrap['Food Waste External Bin']
del(wrap['Food Waste External Bin'])
my_inverted_dict = dict()
for key, value in wrap.items():
my_inverted_dict.setdefault(value, list()).append(key.split(' ')[0])
# my_inverted_dict
target = {}
for k, v in my_inverted_dict.items():
target[f'{k}'] = f'{k}: {", ".join(v)}'
Path('recycling.toml').write_text(toml.dumps(target))
print(target)
return target
if __name__ == '__main__':
get_recycling()
schedule.every(12).hours.do(get_recycling)
while True:
schedule.run_pending()
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment