· 5 years ago · Jan 28, 2021, 11:58 AM
1import json
2import requests
3import math
4
5# Disable insecure warnings
6requests.packages.urllib3.disable_warnings()
7
8# API Key for Testing: k_iqnu3e8z
9
10''' GLOBALS/PARAMS '''
11#PARAMS = demisto.params()
12API_KEY = demisto.params().get('api_key')
13MOVIE_ID = demisto.params().get('movie_id')
14
15# Remove trailing slash to prevent wrong URL path to service
16SERVER = "https://imdb-api.com"
17
18# Should we use SSL
19USE_SSL = not demisto.params().get('insecure', False)
20
21# Service base URL
22BASE_URL = SERVER + '/en/API'
23
24# Headers to be sent in requests
25HEADERS = {}
26
27def http_request(url_suffix, method='POST', data={}, err_operation=None):
28 # A wrapper for requests lib to send our requests and handle requests and responses better
29 #data.update({})
30 res = requests.request(
31 method=method,
32 url=BASE_URL + url_suffix,
33 verify=USE_SSL,
34 data=json.dumps(data),
35 headers=HEADERS
36 )
37 demisto.log(res.content.decode('utf-8'))
38 return json.loads(res.content.decode('utf-8'))
39
40def test_connection():
41 path = "/Title/k_iqnu3e8z/tt0088763"
42 data={}
43 res = http_request(path, method="GET", data=data)
44 return res
45
46 ########################################################
47 ## Actual functions
48 ########################################################
49
50
51
52 def get_title():
53
54 path = "/SearchMovie/k_iqnu3e8z/Inception 2010"
55 data={}
56
57 res = http_request(path, method="GET", data=data)
58 ec = {
59 'Type' : entryTypes['note'],
60 'ContentsFormat' : formats['json'],
61 'Contents': res,
62 'ReadableContentsFormat' : formats['markdown'],
63 'EntryContext' : { imdb['results'][0]['title']
64 }
65 }
66 return ec
67
68
69########################################################
70########################################################
71
72
73 if demisto.command() == 'test-module':
74 res = test_connection()
75
76 if 'result' in res:
77 if 'id' in res['result']:
78 demisto.results('ok')
79 else:
80 demisto.results('Failed')
81 else:
82 demisto.results('test failed')
83
84 elif demisto.command() == 'imdb-get-movie':
85 demisto.results(get_title())
86
87
88
89