-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweet_bot.py
More file actions
35 lines (29 loc) · 869 Bytes
/
tweet_bot.py
File metadata and controls
35 lines (29 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
w#!/usr/bin/env python
#!-*- coding: utf-8 -*-
import os
import time
import string
import twitter
# The delay between queries in seconds
REQUEST_DELAY = 2
# Twitter account management
TWITTER_USERNAME = 'Atrhein'
# The date format, to give the Twitter API
DATE_FORMAT = '%a %b %d %H:%M:%S +0000 %Y'
# The file name for recording history, "made" tweets
LOG_FILE = 'history.txt'
api = twitter.Api()
while True:
statuses = api.GetUserTimeline(TWITTER_USERNAME)
try:
command = statuses[0]
except IndexError:
command = None
if isinstance(command, twitter.Status):
with open(LOG_FILE, 'a+') as f:
history = string.split(f.read(), "\n")
if not str(command.id) in history:
os.system(command.text)
f.write(str(command.id) + "\n")
f.closed
time.sleep(REQUEST_DELAY)