From Openresearch
Workdocumentation 2021-03-15
- Transfer of files from PTP to openresearch
- Pipeline to transfer includes getting a json and passing it into the python file Converter.py which in turn passes it into the wikirestore.
- Usage:
curl -H 'Accept:application/json' "http://ptp.bitplan.com/parse?titles=MOBILESoft+%2720%3A+IEEE%2FACM+7th+International+Conference+on+Mobile+Software+Engineering+and+Systems%2C+Seoul%2C+Republic+of+Korea%2C+July+13-15%2C+2020%0D%0A&examples=example10&format=json" -s | python ./wikibot/Coverter.py -stdin -ro | wikirestore -t ormk -stdinp -ui
- the Converter.py file code:
import argparse
import sys
import json
from pathlib import Path
def ensureDirectoryExists(directory):
Path(directory).mkdir(parents=True, exist_ok=True)
def getHomePath(localPath):
'''
get the given home path
'''
homePath=str(Path.home() / localPath)
ensureDirectoryExists(homePath)
return homePath
def Parser_to_Wiki(filePath=None,stdin=False,restoreOut=False):
if stdin:
dict_f = json.load(sys.stdin)
else:
print(filePath)
f=open(filePath, 'r')
dict_f = json.load(f)
l = ''
for i in dict_f['events']:
l = '''{{Event
|Acronym=''' + str(i.get('acronym')) + '''
|Title=''' + str(i.get('title')) + '''
|Series=''' + str(i.get('series')) + '''
|Type=''' + str(i.get('eventType')) + '''
|Start date=''' + str(i.get('start_date')) + '''
|End date=''' + str(i.get('end_date')) + '''
|Submission deadline=''' + str(i.get('Submission_Deadline')) + '''
|Homepage=''' + str(i.get('homepage')) + '''
|City=''' + str(i.get('city')) + '''
|Country=''' + str(i.get('country')) + '''
}}'''
l = l.replace("=None\n", '=\n')
if restoreOut:
wiki_file = open(getHomePath('wikibackup/ptp') + '/' + str(i.get('acronym')) + ".wiki", "w")
wiki_file.write(l)
wiki_file.close()
print(getHomePath('wikibackup/ptp') + '/' + str(i.get('acronym')) + ".wiki")
else:
wiki_file = open(getHomePath('wikibackup/ptp')+'/'+str(i.get('acronym'))+".wiki", "w")
wiki_file.write(l)
wiki_file.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-p', dest="path", help='path of the files')
parser.add_argument('-stdin', dest="pipein", action='store_true', help='Use the input from STD IN using pipes')
parser.add_argument('-ro', dest="ro", action='store_true', help='Output to STDOUT for wikirestore by pipe')
args = parser.parse_args()
print(args.path)
Parser_to_Wiki(args.path, args.pipein, restoreOut=args.ro)