source: other-projects/metadata-encoding/py/using-api/testSubtitles.py@ 38773

Last change on this file since 38773 was 38773, checked in by jc550, 4 months ago

last batch of python to move

File size: 1.4 KB
Line 
1from habanero import Crossref
2from diophila import OpenAlex
3import sys, argparse, json
4
5cr = Crossref(mailto="[email protected]")
6oa = OpenAlex("[email protected]")
7dateRegex = "[0-9]{4}-{1}[0-9]+-{1}[0-9]+"
8
9doiToCheck = []
10
11def retrieveDOIsWithSubtitles(num):
12 currentDate = "2015-01-01"
13 numCounted = 0
14 while numCounted < num:
15 datasegment = []
16 query = cr.works(filter = {'type' : ['journal-article', 'proceedings-article', 'book-chapter']}, progress_bar=True, sample=100)
17
18 items = query["message"]["items"]
19 for item in items:
20 #print(item["title"][0])
21 if "subtitle" in item.keys():
22 print("Title: " + item["title"][0] + " | Subtitle: " + item["subtitle"][0] + " | DOI: https://doi.org/" + item["DOI"])
23 if item["DOI"] not in doiToCheck:
24 numCounted = numCounted + 1
25 datasegment.append(item["DOI"])
26
27 doiToCheck.append({"dois":datasegment})
28
29def main(argv):
30 parser = argparse.ArgumentParser()
31 parser.add_argument("numberDOIToGet", type=int, help="the number of DOIs that is wanted")
32 parser.add_argument("outputFilePath", help="the output file path")
33 args = parser.parse_args()
34
35 outputFile = open(args.outputFilePath, "w", encoding="utf-8")
36 retrieveDOIsWithSubtitles(args.numberDOIToGet)
37 json.dump({"dataArray": doiToCheck}, outputFile)
38
39if __name__ == "__main__":
40 main(sys.argv)
Note: See TracBrowser for help on using the repository browser.