Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated from submissions #34

Merged
merged 5 commits into from
Oct 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
node_modules
cache
themes/botwiki/statcounter.html
google58822c7cc0900975.html
google58822c7cc0900975.html

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/
17 changes: 17 additions & 0 deletions content/bots/twitterbots/bot_teleport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Title: @bot_teleport
Description: I'm a text bot who teleports you to magical, inspiring places
Author: botsheeter.py
Date: October 15, 2015
Tags: art,nature,fiction,inspiration,inspiring,escapismtinyworlds
Nav: hidden
Robots: index,follow
*/
[![](/content/bots/twitter-bots/images/@bot_teleport.png)](https://twitter.com/bot_teleport)
[@bot_teleport](https://twitter.com/bot_teleport) is a Twitter bot created by [tinyworlds](https://twitter.com/tinyworlds).

A fish with a tophat transporting you to magical, inspiring places.

"bot as escapism, fragments of prose scattered through your day, as a restful place alongside irl"
- George Buckenham

14 changes: 14 additions & 0 deletions content/bots/twitterbots/haikuthegibson.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Title: @haikuthegibson
Description: haiku from the movie Hackers
Author: botsheeter.py
Date: October 15, 2015
Tags: poetry,hackers,movies,opensource,python,prosaic,twitter
Nav: hidden
Robots: index,follow
*/
[![](/content/bots/twitter-bots/images/@haikuthegibson.png)](https://twitter.com/haikuthegibson)
[@haikuthegibson](https://twitter.com/haikuthegibson) is an [open source](https://github.com/nathanielksmith/haikuthegibson) Twitter bot created by [vilmibm](https://twitter.com/nate_smith).

tweets haiku gleaned from the screenplay for the movie Hackers.

Binary file added content/bots/twitterbots/images/bot_teleport.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/bots/twitterbots/images/irememberbot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/bots/twitterbots/images/omg_movies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/bots/twitterbots/images/rule110_bot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions content/bots/twitterbots/irememberbot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Title: @irememberbot
Description: A tribute to Georges Perec's book 'Je me souviens'
Author: botsheeter.py
Date: October 15, 2015
Tags: perec,literature,dreams,memory,memories,book,books
Nav: hidden
Robots: index,follow
*/
[![](/content/bots/twitter-bots/images/@irememberbot.png)](https://twitter.com/irememberbot)
[@irememberbot](https://twitter.com/irememberbot) is a Twitter bot created by [Javier Arce](https://twitter.com/javier).

A tribute to Georges Perec's book 'Je me souviens'.

The bot looks for tweets that contain the phrase "I dreamt [that] I" and transforms them into its own memories, hopefully producing a bizarre list of recollections.

http://blog.javierarce.com/post/124916365329/i-remember-bot

16 changes: 16 additions & 0 deletions content/bots/twitterbots/omg_movies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Title: @omg_movies
Description: A a bot that loves films big time but doesn't have a very good memory.
Author: botsheeter.py
Date: October 15, 2015
Tags: movies,cinema,memory,malapropism,mistakes,fun,puns
Nav: hidden
Robots: index,follow
*/
[![](/content/bots/twitter-bots/images/@omg_movies.png)](https://twitter.com/omg_movies)
[@omg_movies](https://twitter.com/omg_movies) is a Twitter bot created by [Javier Arce](https://twitter.com/javier).

A a bot that loves films big time but doesn't have a very good memory.

It randomly tweets movie titles and actor names with mistakes in them ("I loved Ron Howard's A Beautiful Bind!", "Movie night with Back to the Suture", etc.)

14 changes: 14 additions & 0 deletions content/bots/twitterbots/rule110_bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Title: @rule110_bot
Description: rule 110
Author: botsheeter.py
Date: October 15, 2015
Tags: ruby,math,art,rule110,turing
Nav: hidden
Robots: index,follow
*/
[![](/content/bots/twitter-bots/images/@rule110_bot.png)](https://twitter.com/rule110_bot)
[@rule110_bot](https://twitter.com/rule110_bot) is an [open source](https://github.com/tahnok/rule110) Twitter bot created by [Wesley Ellis](https://twitter.com/tahnok).

It makes art based on https://en.wikipedia.org/wiki/Rule_110 , a 1d cellular automaton that's been proven to be turing complete

200 changes: 200 additions & 0 deletions other/botsheeter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#!/usr/bin/env python
"""
Create markdown entries and screenshots from submissions to:
https://botwiki.org/submit-your-bot
So far only Twitter bots are supported.
"""
from __future__ import print_function, unicode_literals
import argparse
import datetime
import gspread # pip install gspread
import json
import os
from oauth2client.client import SignedJwtAssertionCredentials

# from pprint import pprint


def bot_category(bot):
""" Get the bot's category from its location """
if "twitter.com" in bot['location']:
return "twitter-bots"
return None


def bot_network(bot):
""" Get the bot's network from its location """
if "twitter.com" in bot['location']:
return "Twitter"
return None


def bot_type(bot):
""" Get the bot's type from its location """
if "twitter.com" in bot['location']:
return "twitterbots"
return None


def bot_username(bot, at_sign=False):
""" Get the bot's username from its location """
username = None
if "twitter.com" in bot['location']:
username = bot['location'].rsplit('/', 1)[-1]
if at_sign:
username = "@" + username
return username


def fix_url(url):
""" Check the url really is proper URL """
if url.startswith("twitter.com"):
url = "https://" + url
return url


def format_md(bot):
# bot.network will be deduced based on the URL, eg
# bot.url contains youtube.com => bot.network = 'YouTube'
# and bot.category = 'youtube-bots'
# and bot.type = 'youtubebot'
# etc

date = datetime.datetime.today()
date = date.strftime("%B %d, %Y")

bot['category'] = bot_category(bot)
bot['network'] = bot_network(bot)
bot['type'] = bot_type(bot)
bot['username'] = bot_username(bot, at_sign=True)

print(bot['is_open_source'])
if bot['is_open_source']:
open_source_text = 'n [open source](' + bot['source_url'] + ') '
else:
open_source_text = ' '

if 'creator_twiter_url' in bot:
url = fix_url(bot['creator_twiter_url'])
creator_text = '[' + bot['creator'] + '](' + url + ')'
else:
creator_text = bot['creator']

# Remove spaces from tags
tags = bot['tags'].replace(" ", "")

md_file_text = (
'/*\n'
+ 'Title: ' + bot['username'] + '\n'
+ 'Description: ' + bot['short_description'] + '\n'
+ 'Author: botsheeter.py' + '\n'
+ 'Date: ' + date + '\n'
+ 'Tags: ' + tags + '\n'
+ 'Nav: hidden' + '\n'
+ 'Robots: index,follow' + '\n'
+ '*/' + '\n'
+ '[![](/content/bots/' + bot['category'] + '/images/'
+ bot['username'] + '.png)](' + bot['location'] + ')' + '\n'
+ '[' + bot['username'] + '](' + bot['location'] + ') is a'
+ open_source_text
+ bot['network'] + ' bot created by ' + creator_text + '. \n\n'
+ bot['description'] + '\n\n')
return md_file_text


def bot_md_filename(bot):
""" Return a filename for saving this bot's md file """
return "content/bots/" + bot_type(bot) + "/" + bot_username(bot) + ".md"


def create_dirs(dir):
""" Makes all intermediate-level directories if needed """
if not os.path.isdir(dir):
os.makedirs(dir)


def save_md(md_file_text, filename):
""" Save the md_file_text into filename """
create_dirs(os.path.dirname(filename))
print("Saving to", filename)
with open(filename, "w") as f:
f.write(md_file_text)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Create markdown and screenshots from botwiki submissions",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-j', '--json',
default='E:/Users/hugovk/Dropbox/bin/data/botsheeter.json',
help="JSON file location containing Google OAuth credentials from: "
"https://gspread.readthedocs.org/en/latest/oauth2.html")
args = parser.parse_args()

json_key = json.load(open(args.json))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(
json_key['client_email'], json_key['private_key'].encode(), scope)

gc = gspread.authorize(credentials)

wks = gc.open("Botwiki.org (Responses)").sheet1

list_of_rows = wks.get_all_values()
list_of_rows.pop(0) # ditch header

# Getting stuff to build .md -- only Twitter bots for now
for i, row in enumerate(list_of_rows):
# row is a list of columns
if "twitter" in row[1]:
bot = {}
bot['location'] = row[1]
bot['description'] = row[2]
bot['tags'] = row[3]
bot['active'] = row[4]
if row[5]:
bot['is_open_source'] = True
bot['source_url'] = row[5]
else:
bot['is_open_source'] = False
bot['creator'] = row[6]
bot['short_description'] = row[7]
bot['creator_twiter_url'] = row[8]

outfile = bot_md_filename(bot)
if os.path.isfile(outfile):
continue # Don't overwrite existing

print(bot)
md_file_text = format_md(bot)
print()
print(md_file_text)
print()
save_md(md_file_text, outfile)

# Update the worksheet
# * First value is row number but take care!
# - Rows begin at 1, not 0.
# - Don't forget we ditched the header, so i==0 is row 2.
added_row = i + 2
# * Second value is column (A=1, B=2, etc.)
added_col = 10
wks.update_cell(added_row, added_col, "true")

# Let's find the URLs of Twitter bots
twitter_urls = []
for row in list_of_rows:
if "twitter" in row[1]:
twitter_urls.append(row[1])
print("Found:", row[1])

# Prep botshotter.py call
print("Save images...")
twitter_urls = ",".join(twitter_urls)
import botshotter
outdir = "content/bots/twitterbots/images/" # TODO harcoded for Twitter
create_dirs(outdir)
botshotter.botshotter(twitter_urls, outdir, headless=True)

# End of file
Loading