Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
from requests_html import HTMLSession import json from datetime import datetime import calendar now = datetime.now() current_day = int(now.strftime("%d")) current_month_nr = int(now.strftime("%m")) current_month_name = calendar.month_name[current_month_nr] current_year = int(now.strftime("%Y")) session = HTMLSession() url = "https://www.bexley.gov.uk/services/rubbish-and-recycling/bin-collection-calendar/rotation-week-1" r = session.get(url) # Get all tables with calendar months = r.html.find("table.calendar") # Iterate over every table calendar = {} for month in months: period = month.find('caption')[0].text month_dict = {} for i in month.find('span'): month_dict.update( {int(i.attrs['title'].split(':')[0].split(" ")[1]): i.attrs['title'].split(':')[1].strip()} ) calendar.update( {period:month_dict} ) # Serializing json calendar_json = json.dumps(calendar, indent=4) # Writing to bin_collection.json with open("bin_collection.json", "w") as outfile: outfile.write(calendar_json) # Example: Print output for January 2022, 15 print(f"\n {current_month_name} {current_year}: \n", f"Day {current_day}: ",calendar[f"{current_month_name} {current_year}"][current_day].title(), "\n")
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)