Last active
March 6, 2023 10:10
-
-
Save lzzy12/332d3045807f4a74b86a15d74a1675ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import os | |
import zipfile | |
import sys | |
def getData(path, phone): | |
for path, dirs, files in os.walk(path): | |
for filename in files: | |
if filename[:5] == phone[:5]: | |
fullpath = os.path.join(path, filename) | |
if filename.endswith('.csv'): | |
row = read_csv(filename, fullpath, phone) | |
if row is not None: | |
return row | |
elif filename.endswith('.zip'): | |
print(filename) | |
zip_ref = zipfile.ZipFile(fullpath, 'r') | |
zip_ref.extractall('db/csv/') | |
zip_ref.close() | |
os.remove(fullpath) | |
row = read_csv(filename, 'db/csv/' + filename.replace('zip', 'csv'), phone) | |
if row is not None: | |
return row | |
def read_csv(filename, fullpath, phone): | |
try: | |
csvfile = None | |
print(filename) | |
csvfile = open(fullpath, encoding="utf8") | |
next(csvfile) # Skipping the csv header | |
reader = csv.reader(csvfile, delimiter=',') | |
for row in reader: | |
if row[0] == phone: | |
return row | |
except: | |
print('error') | |
if __name__ == "__main__": | |
try: | |
if phNumber is not None: | |
data = getData(path, phNumber) | |
if data is not None: | |
print(data) | |
else: | |
print("No data found with that number") | |
except IndexError: | |
print('''help: | |
python3 true-caller-search.py [phNumber] [path]''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment