-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
95 lines (67 loc) · 2.27 KB
/
config.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 17 18:13:08 2018
@author: deepaktripathi
"""
from configparser import ConfigParser
filename = 'config.ini'
def read_db_config(section='mysql'):
""" Read database configuration file and return a dictionary object
:param filename: name of the configuration file
:param section: section of database configuration
:return: a dictionary of database parameters
"""
# create parser and read ini configuration file
parser = ConfigParser()
parser.read(filename)
# get section, default to mysql
db = {}
if parser.has_section(section):
items = parser.items(section)
for item in items:
db[item[0]] = item[1]
else:
raise Exception('{0} not found in the {1} file'.format(section, filename))
return db
def read_shady_tlds_config(section='shady.top.level.domains'):
"""
Read shady top level domains.
Currently this is hard coded for POC
We need to curl this regularly and train the model
"""
parser = ConfigParser()
parser.read(filename)
tlds={}
if parser.has_section(section):
for item in parser.items(section):
tlds = item[1]
else:
raise Exception('{0} not found in the {1} file'.format(section, filename))
return tlds
def read_shorten_url_services_config(section="list.of.shorten.url.services"):
"""
Read the list of shorten url services.
"""
parser = ConfigParser()
parser.read(filename)
shorten_url_services={}
if parser.has_section(section):
for item in parser.items(section):
shorten_url_services = item[1]
else:
raise Exception('{0} not found in the {1} file'.format(section, filename))
return shorten_url_services
def read_phishtank_feed_config(section="phishtank_feed"):
parser = ConfigParser()
parser.read(filename)
api_key = ""
api_url = ""
if parser.has_section(section):
api_key=parser[section]['api_key']
api_url=parser[section]['api_url']
return api_key,api_url
if __name__ == '__main__':
api_key , api_url = read_phishtank_feed_config()
print(api_key)
print(api_url)