Unverified Commit 528e4216 authored by Todor Kondic's avatar Todor Kondic
Browse files

pcl: Add depositor , the publishing subsystem

parent d244e837
# Control the process of uploading to Zenodo
import json
import sys
import os
import os.path
import requests
import glob
import mistletoe
import ruamel.yaml as yaml
from mistletoe.ast_renderer import ASTRenderer
# fn_token=os.environ['PCL_ZENODO_TOKEN']
# dir_zenodo=os.environ['']
# dir_work=os.environ['WORKDIR']
zenodo_token=os.environ['PCL_ZENODO_TOKEN']
fn_input=os.environ['PCL_MANIF']
ZEN_DEPO_URL='https://sandbox.zenodo.org/api/deposit/depositions'
HEADERS={'Content-Type': 'application/json'}
with open(fn_input,'r') as fhandle:
conf=yaml.load(fhandle, Loader=yaml.Loader)
depoconf=conf['depositor']
dir_dpr=depoconf['local']
url_zenodo=depoconf['url_zenodo']
fn_publish=dir_dpr+'/publish.md'
print(dir_dpr)
print(url_zenodo)
with open(fn_publish,'r') as fhandle:
with ASTRenderer() as renderer:
content=json.loads(renderer.render(mistletoe.Document(fhandle)))['children']
meta={'description':"",
'creators':{}}
nextisdesc=False
topic=None
listtopic=None
for item in content:
if item.get('level')==1:
meta['title']=item['children'][0]['content']
if item.get('type')=='Heading' and \
item.get('level')==2:
topic=item.get('children')[0]['content']
elif topic=='Description':
if item.get('type')=='Paragraph':
for txt in item.get('children'):
if txt.get('type')=='RawText':
meta['description']+=txt['content']
elif txt.get('type')=='LineBreak':
meta['description']+="\n"
elif txt.get('type')=='Strong':
meta['description']+='**'+txt.get('children')[0].get('content')+'**'
elif txt.get('type')=='Emphasis':
meta['description']+='_'+txt.get('children')[0].get('content')+'_'
elif txt.get('type')=='Link':
meta['description']+='['+txt.get('children')[0].get('content')+']' +\
'('+txt.get('target')+')'
else:
meta['description']+="____UNRECOGNISEDTOKEN____"
meta['description']+="\n" # Divide paragraphs.
elif topic=='Creators':
if item.get('type')=='Heading' and \
item.get('level')==3:
name=item.get('children')[0]['content']
meta['creators'][name]="empty"
# meta['title']=content['Heading']['children']['content']
# meta['description']=
print(meta['creators'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment