-
Notifications
You must be signed in to change notification settings - Fork 1
/
restapi.py
59 lines (52 loc) · 2.13 KB
/
restapi.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
52
53
54
55
56
57
58
from client import RestClient
import json, logging, requests, random
client = RestClient('[email protected]', 'LD87rm8Od9dfWnVn')
# Search class has modules for different functions
class Search():
# https://docs.dataforseo.com/#get-related-keywords
def keywords_related(self, word, location):
rnd = random.Random() #you can set as "index of post_data" your ID, string, etc. we will return it with all results.
post_data = dict()
post_data[rnd.randint(1, 30000000)] = dict(
keyword=word,
country_code=location,
language="en",
depth=1,
limit=2,
offset=0,
orderby="cpc,desc",
filters=[
["cpc", ">", 0],
"or",
[
["search_volume", ">", 0],
"and",
["search_volume", "<=", 1000]
]
]
)
response = client.post("/v2/kwrd_finder_related_keywords_get", dict(data=post_data))
if response["status"] == "error":
print("error. Code: %d Message: %s" % (response["error"]["code"], response["error"]["message"]))
else:
return response["results"]
class Trumpia():
def __init__(self):
self.apiKey = '7f5a72d074cff3222bfa0b079af236fc'
self.username = 'vuskeedoo'
self.header = {'Content-Type':'application/json',
'x-Apikey':self.apiKey}
def sendEmail(self, to_email, msg_body, msg_subject):
url = 'https://api.trumpia.com/rest/v1/' + self.username + '/email'
body = {'from':'[email protected]', 'to':to_email,'subject':msg_subject, 'content_html':msg_body}
try:
resp = requests.request('PUT', url, headers =self.header, json=body)
resp.raise_for_status()
except requests.exceptions.HTTPError as e:
return ('Error: ' + str(e))
if 'request_id' in resp.json():
print('request id returned')
return resp.json()['request_id']
else:
print('request id not returned')
return None