scripts to import data into are.na from other platforms (Tumblr and Pinboard so far)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.3 KiB

# %%
#from arena import Arena
from dotenv import load_dotenv
load_dotenv()
import os
import datetime
import requests
from bs4 import BeautifulSoup
import pinboard
from markdownify import markdownify
#%%
now= datetime.datetime.now()
timestamp = now.strftime('%Y.%m.%d %H:%M')
# %%
def import_metadata(pin):
date = pin.time
link = pin.url
tags = str(pin.tags)
import_info = f'\n------------\n' \
f'Imported from Pinboard on: {timestamp} \n' \
f'Originally saved on {date} \n' \
f'Tags: {tags} \n' \
f'{link}'
return import_info
# %%
pins = pinboard.Pinboard(os.environ['PINBOARD_TOKEN'])
# %%
tagged_pins = pins.posts.all(tag=["book"])
# %%
arena_queue = []
for pin in tagged_pins:
arena_post = {
'source': pin.url,
'description': pin.description + '\n' + pin.extended,
'title': pin.description
}
arena_post['description'] += import_metadata(pin)
arena_queue.append(arena_post)
# pin.description, pin.extended, pin.time
#%% Are.na posting
url = "https://api.are.na/v2/channels/book-inbox/blocks"
arena_queue.reverse()
print('Posting ' + str(len(arena_queue)) + ' blocks')
for block in arena_queue:
block['access_token'] = os.environ['ARENA_TOKEN']
x = requests.post(url, data=block)
print('Done')