kopia lustrzana https://codeberg.org/edent/Mastodon_Tools
45 wiersze
1.6 KiB
Python
Executable File
45 wiersze
1.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
from datetime import datetime, timedelta
|
|
from mastodon import Mastodon
|
|
from bs4 import BeautifulSoup
|
|
|
|
import config
|
|
|
|
# Set up access
|
|
mastodon = Mastodon( api_base_url=config.instance, access_token=config.access_token )
|
|
|
|
# Get user's info
|
|
me = mastodon.me()
|
|
my_id = me["id"]
|
|
year_joined = me["created_at"].year
|
|
|
|
# Today's date
|
|
year_now = datetime.now().year
|
|
month_now = datetime.now().month
|
|
day_now = datetime.now().day
|
|
|
|
# Counter
|
|
year_counter = year_now
|
|
|
|
# Loop through previous years
|
|
# Start with last year and go down until the user joined
|
|
while (year_counter >= year_joined ) :
|
|
year_counter -= 1
|
|
# The end of today is the start of tomorrow
|
|
# This means yesterday can take into account leap-years
|
|
try:
|
|
today_end = datetime(year_counter, month_now, day_now, 00, 00) + timedelta(days=1)
|
|
yesterday_end = today_end - timedelta(days=1)
|
|
# Bitwise shift the integer representation and convert to milliseconds
|
|
max_id = ( int( today_end.timestamp() ) << 16 ) * 1000
|
|
min_id = ( int( yesterday_end.timestamp() ) << 16 ) * 1000
|
|
# Call the API
|
|
statuses = mastodon.account_statuses(id = my_id, max_id=max_id, min_id=min_id, limit="40", exclude_reblogs=True)
|
|
# Fetch further statuses if there are any
|
|
all_statuses = statuses #mastodon.fetch_remaining(statuses)
|
|
# Print the date and URl
|
|
for status in all_statuses :
|
|
print( str(status["created_at"])[:16] + " " + BeautifulSoup(status["content"], features="html.parser").get_text() + " - " + status["uri"] + "\n")
|
|
except:
|
|
print( str(year_counter) + " is not a leap year.")
|
|
|