-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathsupport.py
78 lines (57 loc) · 2.06 KB
/
support.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
69
70
71
72
73
74
75
76
77
78
import sys
import gammu
def load_user_data(filename='credentials.txt'):
users = {}
with open(filename) as credentials:
for line in credentials:
username, password = line.partition(":")[::2]
users[username.strip()] = password.strip()
return users
def init_state_machine(pin, filename='gammu.config'):
sm = gammu.StateMachine()
sm.ReadConfig(Filename=filename)
sm.Init()
if sm.GetSecurityStatus() == 'PIN':
if pin is None or pin == '':
print("PIN is required.")
sys.exit(1)
else:
sm.EnterSecurityCode('PIN', pin)
return sm
def retrieveAllSms(machine):
status = machine.GetSMSStatus()
allMultiPartSmsCount = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed']
allMultiPartSms = []
start = True
while len(allMultiPartSms) < allMultiPartSmsCount:
if start:
currentMultiPartSms = machine.GetNextSMS(Start = True, Folder = 0)
start = False
else:
currentMultiPartSms = machine.GetNextSMS(Location = currentMultiPartSms[0]['Location'], Folder = 0)
allMultiPartSms.append(currentMultiPartSms)
allSms = gammu.LinkSMS(allMultiPartSms)
results = []
for sms in allSms:
smsPart = sms[0]
result = {
"Date": str(smsPart['DateTime']),
"Number": smsPart['Number'],
"State": smsPart['State'],
"Locations": [smsPart['Location'] for smsPart in sms],
}
decodedSms = gammu.DecodeSMS(sms)
if decodedSms == None:
result["Text"] = smsPart['Text']
else:
text = ""
for entry in decodedSms['Entries']:
if entry['Buffer'] != None:
text += entry['Buffer']
result["Text"] = text
results.append(result)
return results
def deleteSms(machine, sms):
list(map(lambda location: machine.DeleteSMS(Folder=0, Location=location), sms["Locations"]))
def encodeSms(smsinfo):
return gammu.EncodeSMS(smsinfo)