This repository was archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain0.py
More file actions
111 lines (89 loc) · 2.87 KB
/
main0.py
File metadata and controls
111 lines (89 loc) · 2.87 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!usr/bin/env python
#########################################################
# #
# Purpose: #
# Read logs and call APIs #
# #
#########################################################
#=======================================================#
import time
import csv
import os
import requests
import json
import sys
import glob
#========================================================#
import apicaller
import filehandler
import updatefile
#========================================================#
contents=updatefile.filebuff()
def find_index(file):
fileobj = open(file)
fileobj_read = csv.reader(fileobj,delimiter=',')
for item in fileobj_read:
index_no1 = item.index('finalCalledPartyNumber')
index_no2 = item.index('callingPartyNumber')
break
fileobj.close()
return index_no1,index_no2
#========================================================#
def find_match(file,no1,no2):
fileobj = open(file)
fileobj_read = csv.reader(fileobj,delimiter=',')
num = '512'#'117484555'
count = 0
f = open('callingPartyNumbers.txt','w+')
#f.write(time.ctime()+'\n')
#f.write('callingPartyNumbers'+'\n')
for item in fileobj_read:
if count == 0:
count+=1
#continue
else:
if num in str(item[no1]):
out = (item[no2])
f.write(out+'\n')
print('logwrite!')
fileobj.close()
# if os.stat('callingPartyNumbers.txt').st_size == 0:
# f.close()
# sys.exit()
# else:
# f.close()
f.close()
#========================================================#
start_time = time.time()
# file_list=os.listdir()
# req_file = max(file_list,key=len)
for content in contents:
filehandler.copyfile(content,r'C:\Script')#.format(filehandler.findfileorig()))
req_file = filehandler.findfile()
# files = glob.glob(r'C:\Script*')
# req_file = max(files,os.path.getctime)
print(req_file)
index1,index2=find_index(req_file)
find_match(req_file,index1,index2)
#========================================================#
with open('callingPartyNumbers.txt') as txtfile:#0 for test purpose
numbers=txtfile.readlines()
#========================================================#
for number in numbers:
if not(apicaller.API1(number)):
if not(apicaller.API2(number)):
apicaller.API4(number)
print('called API4'+':'+number)
else:
p1,p2 = apicaller.API2(number)
apicaller.API3(p1,p2)
print('called API3 from API1'+':'+number)
else:
p3,p4 = apicaller.API1(number)
apicaller.API3(p3,p4)
print('called API3 from API1'+':'+number)
#========================================================#
print('API calling took :'+str(round(time.time()-start_time))+' '+'seconds')
#========================================================#
os.remove(req_file)
filehandler.buffer()