Skip to content

Instantly share code, notes, and snippets.

@cohalz
Created April 13, 2015 06:29
Show Gist options
  • Select an option

  • Save cohalz/d31f0caec77f603f9e1a to your computer and use it in GitHub Desktop.

Select an option

Save cohalz/d31f0caec77f603f9e1a to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
__author__ = 'cohalz'
from twitter import *
import configparser
import random
def tweet(string):
try:
tw.statuses.update(status=string)
except:
tweet(string+"!")
def start(string):
try:
tw.statuses.update(status=string)
print("それナッツ!")
except:
start(string+"!")
config = configparser.ConfigParser()
config.read('nuts.ini')
oauth_config = config['oauth']
oauth = OAuth(
consumer_key=oauth_config['consumer'],
consumer_secret=oauth_config['consumer_secret'],
token=oauth_config['token'],
token_secret=oauth_config['token_secret']
)
tw = Twitter(
auth=OAuth(
oauth_config['token'],
oauth_config['token_secret'],
oauth_config['consumer'],
oauth_config['consumer_secret'])
)
my_name = '@' + tw.account.settings()['screen_name']
start("それナッツ!")
tw_us = TwitterStream(auth=oauth, domain='userstream.twitter.com')
for msg in tw_us.user():
if "text" in msg and (msg['text'].startswith(my_name) or msg['text'].count('それナッツ')) and msg['user']['screen_name'] != 'sorenuts_nuts' :
string = "@"+msg['user']['screen_name']+ " それナッツ"
tweet(string)
tw.favorites.create(_id=msg['id'])
print(msg['text'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment