-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchTitle.py
52 lines (38 loc) · 1.64 KB
/
SearchTitle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from Mylogging import logging
import requests, json
from Maltego2 import *
def trx_searchtitle(m):
TRX = MaltegoTransform()
#me.parseArguments(sys.argv)
title=m.getProperty("title.article")
url = 'http://api.crossref.org/works?query='
r= requests.get(url+title+'&rows=1')
titler = r.json()['message']['items'][0]['title'][0]
doi = r.json()['message']['items'][0]['DOI']
URL = r.json()['message']['items'][0]['URL']
try:
year = str(r.json()['message']['items'][0]['published-print'])
except:
try:
year = str(r.json()['message']['items'][0]['published-online']['date-parts'])
except:
year = str(r.json()['message']['items'][0]['created']['date-parts'])
year = year.translate(None, "{}abcdefghijklmnopqrstuvz':[]-,")
try:
u = r.json()['message']['items'][0]['author']
authori = []
for i in u:
authore = i['family'].encode('utf-8')+' '+i['given'].encode('utf-8')+'; '
authori.append(authore)
except:
authori = []
authori.append(r.json()['message']['items'][0]['publisher'])
new = TRX.addEntity("me.Article", title)
new.addProperty("DOI","DOI", 'strict', str(doi))
new.addDisplayInformation('<a href="%s"> click here to go to the webpage </a>' %URL, 'DOI URL')
new.addProperty("url","url", 'strict', str(URL))
new.addProperty("year","Year", 'strict', str(year))
new.addProperty("author","Author", 'loose', ''.join(authori))
new.setValue(titler.encode('utf-8')) #what the hell is this???????????????????
logging(TRX.returnOutput(),m.Maltegoxml)
return TRX.returnOutput()