-
-
Save gjmf/92e5d717aa6ce268fea5 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
import re | |
import sys | |
import json | |
import requests | |
USER = 'replace_with_your_username' | |
PASS = 'replace_with_your_password' | |
LINE = '7075551212' # your line's phone number | |
PROFILE = 'https://members.sonic.net/labs/fusion-line-profile/' | |
s = requests.Session() | |
# set up the post data | |
payload = {'login': 'login', 'user': USER, 'pw': PASS} | |
# need to have a session cookie before logging in | |
r = s.get('https://members.sonic.net/') | |
# and then actually log in | |
r = s.post('https://members.sonic.net/', data=payload) | |
# get the sync info | |
r = s.post(PROFILE, data={'action': 'ToggleFusionTn', 'FusionTn': LINE}) | |
sync = json.loads(r.text) | |
# DEBUG - dump the json data | |
#print json.dumps(sync, sort_keys=True, indent=4) | |
fusion_mode = sync['fusion_this_mode'] | |
sync_mode = sync['sync_this_mode'] | |
if len(sys.argv) == 1 or sys.argv[1].lower() in ['stat', 'status', 'info', 'show']: | |
print 'Mode: %s' % (fusion_mode) | |
print 'Sync: %s' % (sync_mode) | |
line_n = 1 | |
total_down = 0 | |
total_up = 0 | |
for pair in sorted(filter(lambda x: re.match(r'^pair_info', x), sync.keys())): | |
info = sync[pair].values()[0] | |
status = info['link_status'] | |
down = info['downstream_sync_rate'] | |
up = info['upstream_sync_rate'] | |
print 'Line %u: %6ukbps %6ukbps %4s' % (line_n, down, up, status) | |
line_n += 1 | |
total_down += down | |
total_up += up | |
print 'Total: %6ukbps %6ukbps' % (total_down, total_up) | |
elif fusion_mode == 'Download' and sys.argv[1].lower() in ['annexm', 'upload']: | |
r = s.post(PROFILE, data={'action': 'SetFusionMode', 'FusionTn': LINE}) | |
print "Service switched to AnnexM (upload). Resync may take a minute or two." | |
elif fusion_mode == 'Upload' and sys.argv[1].lower() in ['annexa', 'download']: | |
r = s.post(PROFILE, data={'action': 'SetFusionMode', 'FusionTn': LINE}) | |
print "Service switched to AnnexA (download). Resync may take a minute or two." | |
elif sync_mode == 'Interleave' and sys.argv[1].lower() in ['fastpath']: | |
r = s.post(PROFILE, data={'action': 'SetSyncMode', 'FusionTn': LINE}) | |
print "Service switched to Fastpath (low latency). Resync may take a minute or two." | |
elif sync_mode == 'Fastpath' and sys.argv[1].lower() in ['interleave']: | |
r = s.post(PROFILE, data={'action': 'SetSyncMode', 'FusionTn': LINE}) | |
print "Service switched to Interleave (robust). Resync may take a minute or two." | |
else: | |
print "No action taken (invalid command or service already in specified configuration)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment