-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
68 lines (56 loc) · 1.76 KB
/
app.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
import os
import shutil
print(
"\n"
+ "===" * 30
+ "\n Simple android contact adder. Press enter to quit script.\n"
+ "===" * 30
+ "\n"
)
def add_contact():
while True:
new_contact_num = str(input("Enter phone number: "))
if len(new_contact_num) != 10:
print("Phone number not 10 digits")
continue
new_contact_fn = input("Enter first name: ")
new_contact_ln = input("Enter last name: ")
# Formatting phone number to add '_'
temp = "-".join(
new_contact_num[i : i + 3] for i in range(0, len(new_contact_num) - 3, 3)
)
new_num = temp + new_contact_num[-1]
data = f"""BEGIN:VCARD
VERSION:2.1
N:{new_contact_ln};{new_contact_fn};;;
FN:{new_contact_fn} {new_contact_ln}
TEL;CELL:{new_num}
END:VCARD"""
try:
with open("contacts.vcf", "a+") as f:
f.write(data)
print("Added contact.")
except:
print("Couldn't add contact.")
break
backup()
def backup():
# Backup contacts.vcf
if os.path.exists("contacts.vcf"):
# get the path to the file in the current directory
src = os.path.realpath("contacts.vcf")
# seperate the path from the filter
# head, tail = os.path.split(src)
# print("path:" + head)
# print("file:" + tail)
# let's make a backup copy by appending "bak" to the name
dst = src + ".bak"
# now use the shell to make a copy of the file
shutil.copy(src, dst)
# copy over the permissions,modification
shutil.copystat(src, dst)
print("backed up files to", src)
add_contact()
if __name__ == "__main__":
while True:
add_contact()