Skip to content

Instantly share code, notes, and snippets.

@jen6
Created October 22, 2017 10:47
Show Gist options
  • Save jen6/cc9dc85783040840667f70e971fc6186 to your computer and use it in GitHub Desktop.
Save jen6/cc9dc85783040840667f70e971fc6186 to your computer and use it in GitHub Desktop.
import subprocess
#import urllib
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
import time
import json
kHerokuUrl = "http://lit-castle-67838.herokuapp.com"
delayTime = 5
#check connection
while True:
try:
req = urlopen(kHerokuUrl, timeout=10)
break
except (HTTPError, URLError) as e:
print("wtf")
time.sleep(delayTime)
#get ifconfig
proc = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
local_time = time.asctime( time.localtime(time.time()) ) + '\n'
buf = out+bytes(local_time, 'utf-8')
#send output of ifconfig + localtime
data = {'data':buf}
sdata = bytes( urlencode(data).encode())
req = Request(kHerokuUrl + "/user/jen6", data=sdata)
resp = urlopen(req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment