Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Github repo cloud-examples: https://github.com/sagemath/cloud-examples

Views: 7955
License: MIT
%auto # AUTHOR: Maarten Derickx import urllib2 import json @interact def xkcd(n=""): file = None data = None url = "http://dynamic.xkcd.com/api-0/jsonp/comic/%s"%n try: file = urllib2.urlopen(url) data=file.read() except urllib2.HTTPError: pass finally: if file: file.close() if data: data=json.loads(data) img=data['img'] alt=data['alt'] title=data['safe_title'] link="http://xkcd.com/%s"%n html('<h1>%s</h1><img src="%s" title="%s" ><div>Source: <a href="%s" target="_blank">%s</a></div>'%(title,img,alt,link,link)) return raise RuntimeError,"Could not obtain comic data from %s . Maybe you should enable time travel!"%url
Interact: please open in CoCalc