-
Notifications
You must be signed in to change notification settings - Fork 7
/
curser.py
48 lines (41 loc) · 1.45 KB
/
curser.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
import os
import requests, time, csv, ast, sys, MySQLdb, os
import out1_pro,os
import EditDistance
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
add_record = "INSERT INTO nameemail (email, name, info, website) VALUES (%s, %s, %s, %s)"
def fire(name="", email="", info="", site=''):
global add_record, cursor, cnx
data_record = (email, name, info, site)
cursor.execute(add_record, data_record )
cnx.commit()
folders = []
i = 0
def recurse(folder):
global i, folders
for root, subdirs, files in os.walk(folder):
i += 1
if i ==1:
folders = subdirs
def recursion(path2, folder):
for root, subdirs, files in os.walk(path2):
for filename in files:
if filename[-4:] == ".xml":
path = os.path.join(root, filename)
text,emails = out1_pro.callMe(path)
if text != None:
w = EditDistance.textToMapping(text,emails)
for item in w:
# print(item, w[item],filename[:-4], folder)
try:
fire(w[item], item, filename[:-4], folder)
except Exception as e:
print("Exception in database updation " + str(e))
def recurse2(path):
global folders
recurse(path)
for folder in folders:
path2 = os.path.join(path, folder)
recursion(path2, folder)
# recurse2(os.getcwd())