Skip to content

Instantly share code, notes, and snippets.

@pythonanywhere
Last active June 22, 2017 18:11
Show Gist options
  • Save pythonanywhere/5502596 to your computer and use it in GitHub Desktop.
Save pythonanywhere/5502596 to your computer and use it in GitHub Desktop.
PythonAnywhere Gist DemoBot
import os
import subprocess
def get_google_news_homepage():
print("this will fetch the current google news home page as text.")
print("it will use the requests and lxml libaries")
print("press enter to continue")
input()
import requests
from lxml import html
page_raw = requests.get('http://www.news.google.com').content
parsed = html.fromstring(page_raw)
print(
'\n'.join(
line for line in
parsed.cssselect('body')[0].text_content().split('\n')
if "{" not in line and ";" not in line and "}" not in line
)
)
print("phew! what a lot of news... and *so* readable in this format!")
print("check out out show_batteries_included next? or maybe type '?' to see IPython's help?")
def show_batteries_included(python_version=2.7):
if python_version not in (2.6, 2.7, 3.3, 3.4):
return "only pythons 2.6, 2.7, 3.3 and 3.4 'mafraid"
print(subprocess.check_output(["/usr/local/bin/pip" + str(python_version), "freeze"]).decode("utf-8"))
def schemers_easter_egg():
get_ipython().system(u'guile')
import sys
import time
def print_with_pause(some_text=''):
print(some_text)
sys.stdout.flush()
time.sleep(0.6)
print("\n")
for _ in range(5):
print(".", end="")
sys.stdout.flush()
time.sleep(0.3)
print_with_pause()
print("Hello, World!")
print_with_pause()
print_with_pause()
print_with_pause()
print_with_pause("I am a Gist console on PythonAnywhere")
print_with_pause()
print_with_pause("I am running the code from a gist stored on github")
print_with_pause()
print_with_pause()
print_with_pause()
print_with_pause(
"Why would you want me? Well, maybe you want to share a bit of "
"code with someone, but you also want them to be able to try it out in "
"a console"
)
print_with_pause("You might use it to post solutions to StackOverflow questions for example..")
print_with_pause("Or maybe you've written a mini-library you want to show off on your website")
print_with_pause("Or a tutorial perhaps... who knows?")
print_with_pause()
print_with_pause()
print_with_pause(
"I am running in a fairly fully-featured linux sandbox. There's a filesystem..."
)
print_with_pause("Here is os.listdir('.') and os.listdir('/')")
import os
print_with_pause(os.listdir('.'))
print_with_pause(os.listdir('/'))
print_with_pause()
print_with_pause()
print_with_pause(
"I can access the Internet (via a proxy server with a whitelist)..."
)
print_with_pause()
print_with_pause(
"And I can access all the pre-installed modules supported by PythonAnywhere"
)
print_with_pause()
print_with_pause(
"When I finish loading the default code from the gist, I leave the user "
"in interactive mode so they can play around"
)
print_with_pause()
print_with_pause(
"Try me now! You're in an IPython shell, so things will tab-complete"
)
print_with_pause(
"Here's a few functions I'm making available to you\n"
" get_google_news_homepage()\n"
" show_batteries_included(python_version=2.7)\n"
" schemers_easter_egg()\n"
)
print_with_pause()
print_with_pause()
print_with_pause(
"And check the info bar on the left for instructions on how to make your own Gist consoles"
)
from extra_functions import get_google_news_homepage, show_batteries_included, schemers_easter_egg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment