Created
May 4, 2018 23:38
-
-
Save tshirtman/ac88dba141c101329f099da543b07e36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.network.urlrequest import UrlRequest | |
KV = ''' | |
BoxLayout: | |
orientation: 'vertical' | |
Label: | |
id: result | |
Button: | |
size_hint_y: None | |
height: 40 | |
text: 'press' | |
on_release: app.get_info() | |
''' | |
class TestApp(App): | |
def build(self): | |
return Builder.load_string(KV) | |
def got_json(self, req, result): | |
label = self.root.ids.result | |
print(result) | |
for key, value in result.items(): | |
label.text += ('{}: {}'.format(key, value)) | |
print('{}: {}'.format(key, value)) | |
def fail(self, *args): | |
print(args) | |
def get_info(self): | |
print("making request") | |
self.get_url('http://xkcd.com/614/info.0.json') | |
def get_url(self, url): | |
self.req = UrlRequest( | |
url, | |
on_success=self.got_json, | |
on_error=self.fail, | |
on_failure=self.fail, | |
on_progress=self.progress, | |
on_redirect=self.follow, | |
) | |
def progress(self, *args): | |
print("beep boop", args) | |
def follow(self, req, result): | |
self.get_url(req.resp_headers['location']) | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment