Skip to content
Open
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
59 changes: 36 additions & 23 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import tweepy, re, requests, random, traceback, time
from secrets import *
import tests as t
import random
import re
import requests
import time
import traceback

from bs4 import BeautifulSoup
import tweepy
from tweepy.streaming import StreamListener
from myAPI import *

from myAPI import myAPI #*
from secret import *
import tests as t


class listener_tweeter(StreamListener):
def _onconnect(self):
print 'Connected! Listening...'
print('Connected! Listening...')

# override on_status to pass data from on_data method of tweepy's StreamListener
def on_status(self, status):
print '{} said: "{}"'.format(status.user.screen_name, status.text)
print('{} said: "{}"'.format(status.user.screen_name, status.text))

# ignore retweets or tweets from self
if status.retweeted or ( status.user.screen_name == 'ProfessorSet' ):
Expand All @@ -25,18 +32,19 @@ def on_status(self, status):
# without outlining specific sets
try:
tweet_url = re.search(r'https:.*\b', status.text).group(0)
with_sets_outlined = (False if re.search(r'sets or not', status.text) else True)
with_sets_outlined = not bool(re.search(r'sets or not', status.text)) # "sets or not" == no outlines

text, img_str = solve_tweeted_set(tweet_url, with_sets_outlined=with_sets_outlined)

#ignore tweets with no image
except AttributeError:
except AttributeError as e:
print(repr(e))
text = "You forgot a picture, {} #whoops #howembarrassing".format(status.user.name)
n = random.randint(0, 140-len(text))
text += '!'*n

response_text = '.@{} {}'.format(status.user.screen_name, text)
print response_text
print(response_text)

try:
response = api.retweet(id=status.id)
Expand All @@ -45,22 +53,22 @@ def on_status(self, status):
traceback.print_exc()

# try to avoid posting tweets out of order (should be retweet, then response tweet)
for i in xrange(10):
for _ in range(10):
if response:
send_tweet( response_text, response_id=status.id, media_str=img_str )
send_tweet(response_text, response_id=status.id, media_str=img_str)
return
else:
time.sleep(10)

# but ultimately just send it anyway
send_tweet( response_text, response_id=status.id, media_str=img_str )
send_tweet(response_text, response_id=status.id, media_str=img_str)


def on_error(self, status_code):
print 'Error: {}'.format(status_code)
print('Error: {}'.format(status_code))

def on_exception(self, exception):
print 'Exception: {}'.format(exception)
print('Exception: {}'.format(exception))
return


Expand Down Expand Up @@ -102,20 +110,23 @@ def solve_tweeted_set(tweet_url, with_sets_outlined=True):
img_url = soup.find('meta', attrs={'property': 'og:image'})['content']

# find Sets
kwargs = {'path_is_url': True, 'pop_open': False}
kwargs['draw_contours'] = (True if with_sets_outlined else False)
kwargs['sets_or_no'] = (False if with_sets_outlined else True)
kwargs = {
'path_is_url': True,
'pop_open': False,
'draw_contours': with_sets_outlined,
'sets_or_no': not with_sets_outlined
}
num_sets, initial_img_str = t.play_game(img_url, **kwargs)

# send string with media_data (rather than media) tag because it is base64 encoded
img_str = 'media_data={}'.format(initial_img_str)

text = ("Whoa! {} sets #craycray".format(num_sets) if num_sets \
else "No sets #bummer #sadface")
text = ("Whoa! {} sets #craycray".format(num_sets)
if num_sets else "No sets #bummer #sadface")

img_str = (img_str if num_sets else None)
img_str = img_str if num_sets else None

return (text, img_str)
return text, img_str



Expand All @@ -124,7 +135,8 @@ def send_tweet(text, response_id=None, media_str=None):
text = text[:140]
d_arguments = {'status': text}

if response_id: d_arguments['in_reply_to_status_id'] = response_id
if response_id:
d_arguments['in_reply_to_status_id'] = response_id

if media_str:
upload = api.media_upload(file=media_str, filename='filenames_are_for_dweebs')
Expand All @@ -142,7 +154,8 @@ def send_tweet(text, response_id=None, media_str=None):
def listen():
my_listener = listener_tweeter()
stream = tweepy.Stream(auth, my_listener)
stream.userstream(_with='user')
#stream.userstream(_with='user')
stream.filter(follow=[BOT_ID])



Expand Down
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
PROP_TEXTURE_STRIPED = 1
PROP_TEXTURE_EMPTY = 2
PROP_TEXTURE_SOLID = 3
PROP_TEXTURE_MAP = ['_', 'STRIPED', 'EMPTY', 'SOLID']
PROP_TEXTURE_MAP = ['_', 'STRIPED', 'EMPTY', 'SOLID']
6 changes: 4 additions & 2 deletions experiments.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import cv2
import cv2.cv as cv
import sys

import cv2
#import cv2.cv as cv
import numpy as np

from util import show, destroy


CARD_SIZE_WIDTH = 64
CARD_SIZE_HEIGHT = 89
CARD_SIZE_RATIO = CARD_SIZE_WIDTH/CARD_SIZE_HEIGHT
Expand Down
3 changes: 2 additions & 1 deletion myAPI.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tweepy import API
#from tweepy.binder import bind_api
from mybinder import my_bind_api
from tweepy import API


class myAPI(API):
@staticmethod
Expand Down
5 changes: 3 additions & 2 deletions mybinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Copyright 2009-2010 Joshua Roesslein
# See LICENSE for details.

from __future__ import print_function
#from __future__ import print_function

import time
import re

from six.moves.urllib.parse import quote
#from six.moves.urllib.parse import quote
from urllib.parse import quote
import requests

import logging
Expand Down
141 changes: 128 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,128 @@
cv2==1.0
funcsigs==0.4
matplotlib==1.4.3
mock==1.3.0
nose==1.3.7
numpy==1.10.1
pbr==1.8.1
pyparsing==2.0.3
python-dateutil==2.4.2
pytz==2015.6
requests==2.8.1
six==1.10.0
wheel==0.24.0
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
asn1crypto=0.24.0=py36_0
atk=2.25.90=h05f3006_1
backcall=0.1.0=py36_0
beautifulsoup4=4.6.3=py36_0
blas=1.0=mkl
blinker=1.4=py_1
bzip2=1.0.6=h470a237_2
ca-certificates=2018.03.07=0
cairo=1.14.12=h276e583_5
certifi=2018.11.29=py36_0
cffi=1.11.5=py36he75722e_1
chardet=3.0.4=py36_1
cryptography=2.4.1=py36h1ba5d50_0
cryptography-vectors=2.3.1=py36_1000
cycler=0.10.0=py36_0
dbus=1.13.2=h714fa37_1
decorator=4.3.0=py36_0
expat=2.2.5=hfc679d8_2
ffmpeg=4.0.2=ha0c5888_2
fontconfig=2.13.1=h65d0f4c_0
freetype=2.9.1=h6debe1e_4
funcsigs=1.0.2=py36_0
gdk-pixbuf=2.36.12=h4ab6910_1
gettext=0.19.8.1=h5e8e0c9_1
giflib=5.1.4=h470a237_1
glib=2.56.2=h464dc38_1
gmp=6.1.2=hfc679d8_0
gnutls=3.5.19=h2a4e5f8_1
gobject-introspection=1.56.1=py36haaf12d0_1
graphite2=1.3.12=hfc679d8_1
gst-plugins-base=1.14.0=hbbd80ab_1
gstreamer=1.14.0=hb453b48_1
gtk2=2.24.31=hde048ef_0
harfbuzz=1.9.0=h04dbb29_1
hdf5=1.10.2=hba1933b_1
icu=58.2=hfc679d8_0
idna=2.7=py36_0
intel-openmp=2019.1=144
ipython=7.2.0=py36h39e3cac_0
ipython_genutils=0.2.0=py36_0
jasper=1.900.1=hff1ad4c_5
jedi=0.13.1=py36_0
jpeg=9c=h470a237_1
kiwisolver=1.0.1=py36hf484d3e_0
libffi=3.2.1=hfc679d8_5
libgcc=7.2.0=h69d50b8_2
libgcc-ng=8.2.0=hdf63c60_1
libgfortran=3.0.0=1
libgfortran-ng=7.3.0=hdf63c60_0
libiconv=1.15=h470a237_3
libpng=1.6.36=ha92aebf_0
libstdcxx-ng=8.2.0=hdf63c60_1
libtiff=4.0.10=he6b73bb_0
libuuid=2.32.1=h470a237_2
libwebp=0.5.2=7
libxcb=1.13=h470a237_2
libxml2=2.9.8=h422b904_5
libxslt=1.1.32=h1312cb7_0
lxml=4.2.5=py36hefd8a0e_0
matplotlib=2.2.2=py36hb69df0a_2
mkl=2018.0.3=1
mkl_fft=1.0.6=py36h7dd41cf_0
mkl_random=1.0.1=py36h4414c95_1
mock=2.0.0=py36_0
ncurses=6.1=hfc679d8_1
nettle=3.3=0
nose=1.3.7=py36_2
numpy=1.15.4=py36h1d66e8a_0
numpy-base=1.15.4=py36h81de0dd_0
oauthlib=2.1.0=py_0
olefile=0.46=py36_0
openblas=0.2.20=8
openh264=1.8.0=hd28b015_0
openssl=1.1.1a=h7b6447c_0
pango=1.40.14=he752989_2
parso=0.3.1=py36_0
pbr=5.1.1=py36_0
pcre=8.42=h439df22_0
pexpect=4.6.0=py36_0
pickleshare=0.7.5=py36_0
pillow=5.3.0=py36h34e0f95_0
pip=18.1=py36_1000
pixman=0.34.0=h470a237_3
prompt_toolkit=2.0.7=py36_0
pthread-stubs=0.4=h470a237_1
ptyprocess=0.6.0=py36_0
pycparser=2.19=py36_0
pygments=2.2.0=py36_0
pyjwt=1.6.4=py_0
pyopenssl=18.0.0=py36_0
pyparsing=2.3.0=py36_0
pyqt=5.6.0=py36_2
pysocks=1.6.8=py36_0
python=3.6.7=h0371630_0
python-dateutil=2.7.5=py36_0
pytz=2018.7=py36_0
qt=5.6.3=h8bf5577_3
readline=7.0=haf1bffa_1
requests=2.20.1=py36_0
requests-oauthlib=1.0.0=py_1
setuptools=40.6.2=py36_0
sip=4.19.8=py36hf484d3e_0
six=1.11.0=py36_1
sqlite=3.26.0=hb1c47c0_0
tk=8.6.9=ha92aebf_0
tornado=5.1.1=py36h7b6447c_0
traitlets=4.3.2=py36_0
urllib3=1.23=py36_0
wcwidth=0.1.7=py36_0
wheel=0.32.3=py36_0
x264=1!152.20180717=h470a237_1
xorg-kbproto=1.0.7=h470a237_2
xorg-libice=1.0.9=h470a237_4
xorg-libsm=1.2.3=h8c8a85c_0
xorg-libx11=1.6.6=h470a237_0
xorg-libxau=1.0.8=h470a237_6
xorg-libxdmcp=1.1.2=h470a237_7
xorg-libxext=1.3.3=h470a237_4
xorg-libxrender=0.9.10=h470a237_2
xorg-libxt=1.1.5=h470a237_2
xorg-renderproto=0.11.1=h470a237_2
xorg-xextproto=7.3.0=h470a237_2
xorg-xproto=7.0.31=h470a237_7
xz=5.2.4=h470a237_1
zlib=1.2.11=h470a237_3
6 changes: 6 additions & 0 deletions secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
C_KEY = "uULgOqxGCfDmG68grUFuH3JLa"
C_SECRET = "OY6y8IRXvt2qACY4Riq2OOB79Ez8LElINSVkC63dpNG9qigsz3"
A_TOKEN = "4054224353-suw7Yufiq0ZCBqoXE6jBIgvX2uHGSfNdP5Bu2pZ"
A_TOKEN_SECRET = "oByn1rEaCuyKUoJ7x8Vbf1iDJOUk1brsEkh82fzoHeRgT"

BOT_ID = "4054224353"
Loading