-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsender.py
73 lines (59 loc) · 1.75 KB
/
sender.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
from db import Db
from config import *
import json, csv
class Sender():
"""
Sender
* domain
* name
* insert
* get_by_domain
* json
"""
def __init__(self, data=None):
if data == None:
self._domain = ''
self._name = ''
else:
self._domain = data['domain']
self._name = data['name']
def __repr__(self):
return f'Sender: {self.domain()} - {self.name()}'
def domain(self):
return self._domain
def name(self):
return self._name
def insert(self, verbose=False):
db = Db()
sql = 'INSERT INTO sender (domain, name) VALUES (%s, %s);'
data = [self.domain(), self.name()]
db.query(sql, data, verbose)
def get_by_domain(self, domain):
db = Db()
sql = 'SELECT * FROM sender WHERE domain = %s;'
data = [domain]
result = db.query(sql, data)
if result is not None:
self._domain, self._name = result['domain'], result['name']
def json(self):
data = {'domain': self.domain(), 'name': self.name()}
return json.dumps(data)
if __name__=='__main__':
pass
"""
# Creating GoldList from CSV
fn = "/Users/grayden/Downloads/Gold list for google promo - for Grayden.csv"
with open(fn, 'r') as f:
reader = csv.DictReader(f)
domains = []
for i, row in enumerate(reader):
if row['domain'] not in domains:
data = {'domain': row['domain'], 'name': row['name']}
s = Sender(data)
s.insert(True)
domains.append(s.domain())
"""
# get_by_domain
#s = Sender()
#s.get_by_domain('sethgodin.com')
#print(s)