1 | from habanero import Crossref
|
---|
2 | from diophila import OpenAlex
|
---|
3 | import sys, argparse, json
|
---|
4 |
|
---|
5 | cr = Crossref(mailto="[email protected]")
|
---|
6 | oa = OpenAlex("[email protected]")
|
---|
7 | dateRegex = "[0-9]{4}-{1}[0-9]+-{1}[0-9]+"
|
---|
8 |
|
---|
9 | doiToCheck = []
|
---|
10 |
|
---|
11 | def 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 |
|
---|
29 | def 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 |
|
---|
39 | if __name__ == "__main__":
|
---|
40 | main(sys.argv) |
---|