kopia lustrzana https://codeberg.org/edent/Mastodon_Tools
Added On This Day
rodzic
749700fae0
commit
3a91fca61d
|
@ -0,0 +1,38 @@
|
|||
from datetime import datetime, timedelta
|
||||
from mastodon import Mastodon
|
||||
|
||||
# Set up access
|
||||
instance = "https://mastodon.example"
|
||||
mastodon = Mastodon( api_base_url=instance, access_token="abc123" )
|
||||
|
||||
# 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
|
||||
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 = mastodon.fetch_remaining(statuses)
|
||||
# Print the date and URl
|
||||
for status in all_statuses :
|
||||
print( str(status["created_at"]) + " " + status["uri"] )
|
Ładowanie…
Reference in New Issue