Initial Commit

This commit is contained in:
minecraftchest1@outlook.com 2025-04-29 13:12:05 -05:00
commit 5255291932
2 changed files with 63 additions and 0 deletions

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
phonenumbers==9.0.3
vobject==0.9.9
Flask==3.1.0
requests==2.32.3

59
vcard-http.py Normal file
View file

@ -0,0 +1,59 @@
import argparse
import codecs
import json
import os
import phonenumbers
import requests
from requests.auth import HTTPDigestAuth
import urllib.request
import vobject
from flask import Flask
app = Flask(__name__)
contactsFile = '/tmp/cache.vcf'
#contactsFile = os.envrion['VCARD_HTTP_URL']
#def main():
# parser = argparse.ArgumentParser(description='Get contacts phone number from csv file.')
# parser.add_argument('filename', help='path to csv file to read from')
# parser.add_argument('contact_name', help='contact name to retrieve number for')
# args = parser.parse_args()
def updateCache():
#with urllib.request.urlopen(os.envrion['VCARD_HTTP_URL'])
with open(contactsFile, "wb") as f:
f.write(requests.get(
'https://nextcloud.minecraftchest1.us/remote.php/dav/addressbooks/users/9788b3b83b62eae1fb3646eb59b8385ca3180989fcfa515a632f481c567f2e7c/contacts/?export',
auth=('9788b3b83b62eae1fb3646eb59b8385ca3180989fcfa515a632f481c567f2e7c', 'txmHW-dwBFz-eqqf4-mbkct-rKL58')).content)
@app.route("/search/<contactName>")
def index(contactName):
obj = vobject.readComponents(codecs.open(contactsFile, encoding='utf-8').read())
contacts = [contact for contact in obj]
outJson = []
for contact in contacts:
if contactName.lower() in contact.fn.value.lower():
contactJson = {}
contactJson.update({'name': contact.fn.value})
numbers = []
for tel in contact.contents["tel"]:
number = phonenumbers.parse(tel.value, "US")
numbers.append({"type": tel.params.get("TYPE")[0], "number": phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.E164)})
contactJson.update({'numbers': numbers})
outJson.append(contactJson)
outJsonS = json.dumps(outJson)
return outJson
#print(outJsonS)
@app.route("/cache")
def cache():
updateCache()
with open(contactsFile, "r") as f:
return f.read()