-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
46 lines (38 loc) · 1.21 KB
/
server.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
#!/usr/bin/env python
from twython import Twython
import aprslib
import configparser
config = ConfigParser()
config.read('key.txt')
APP_KEY = config.get('Twitter', 'APP_KEY')
APP_SECRET = config.get('Twitter', 'APP_SECRET')
OAUTH_TOKEN = config.get('Twitter', 'OAUTH_TOKEN')
OAUTH_TOKEN_SECRET = config.get('Twitter', 'OAUTH_TOKEN_SECRET')
call = config.get('APRS', 'call')
passwd = config.get('APRS', 'pass')
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
import aprslib
import re
def start():
try:
aprs = aprslib.IS(call, passwd=passwd)
aprs.connect()
# send a packet
#aprs.sendall("TWITR>APRS,TCPIP*:>Python HamRadioTweets Server Started")
#tweet('Python Dev Server Started')
aprs.consumer(parse, raw=True)
except:
start()
def parse(packet):
spack = str(packet)
regexp = re.compile('TWITR') #change callsign
if regexp.search(spack):
strip1 = re.sub(r'>.+TWITR\s+:', ':', spack) #change callsign
strip2 = re.sub(r'b.', '', strip1)
msg = re.sub(r'.\Z', '', strip2)
tweet(msg) #Tweet immediately after parsing
else:
pass
def tweet(status):
twitter.update_status(status=status)
start()