initial commit
This commit is contained in:
commit
40b896d944
4 changed files with 56912 additions and 0 deletions
51
indy.py
Normal file
51
indy.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from mastodon import Mastodon
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import pause
|
||||
import json
|
||||
|
||||
data = json.load(open('sorted.json'))
|
||||
|
||||
# Set up Mastodon
|
||||
mastodon = Mastodon(
|
||||
api_base_url = 'https://mastodon.cisti.org',
|
||||
access_token = 'token.secret'
|
||||
)
|
||||
|
||||
for post in data:
|
||||
|
||||
# add 20 years
|
||||
dt = datetime.fromisoformat(post['created'])
|
||||
dt = dt.replace(year=2021)
|
||||
|
||||
# skip past post
|
||||
if dt < datetime.now():
|
||||
print("Skip ", post['heading'], dt)
|
||||
continue
|
||||
|
||||
# wait for the next post
|
||||
print("Next post at: ", dt, post['heading'])
|
||||
pause.until(dt)
|
||||
|
||||
# FINAL URL
|
||||
url = "https://italy.indymedia.org/posts/"+post['hugo']
|
||||
out = post['created'] +"\n\n"+post['heading']+"\n\n"
|
||||
|
||||
# CHECK MEDIA LINK
|
||||
media_id = False
|
||||
if post['linked_file']:
|
||||
# MEDIA LINK URL
|
||||
linkurl = "https://italy.indymedia.org/uploads/"
|
||||
# IMAGES ONLY
|
||||
if post['linked_file'].lower().find('jpg') >= 0 or \
|
||||
post['linked_file'].lower().find('jpeg') >= 0 or \
|
||||
post['linked_file'].lower().find('gif') >= 0:
|
||||
response = requests.get("https://italy.indymedia.org/uploads/" + post['linked_file'])
|
||||
with open('./tmp', 'wb') as f:
|
||||
f.write(response.content)
|
||||
media_id = mastodon.media_post('./tmp')
|
||||
|
||||
media_ids = [media_id] if media_id else []
|
||||
out += 'LEGGI IL POST: '+url
|
||||
print(out)
|
||||
mastodon.status_post(out, visibility='private', media_ids=media_ids)
|
7
json_sorter.js
Normal file
7
json_sorter.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
const a = require('./luglio_2001-bot.json')
|
||||
const dayjs = require('dayjs')
|
||||
const fs = require('fs')
|
||||
|
||||
const r = a.sort((a,b) => dayjs(`${a.date} ${a.time}`)-dayjs(`${b.date} ${b.time}`) )
|
||||
fs.writeFileSync('./sorted.json', JSON.stringify(r, null, 2))
|
||||
|
28427
luglio_2001-bot.json
Normal file
28427
luglio_2001-bot.json
Normal file
File diff suppressed because it is too large
Load diff
28427
sorted.json
Normal file
28427
sorted.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue