Skip to content

Instantly share code, notes, and snippets.

@scateu
Last active December 19, 2015 02:29
Show Gist options
  • Save scateu/5883144 to your computer and use it in GitHub Desktop.
Save scateu/5883144 to your computer and use it in GitHub Desktop.
THUTreehole_auto
# -*- coding:utf-8 -*-
import urllib2
import urllib
import cookielib
import httplib
import linecache
import random
def Say(words):
print words
cookieJar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
f = opener.open("http://www.thutreehole.tk/")
csrftoken = cookieJar._cookies['www.thutreehole.tk']['/']['csrftoken'].value
print csrftoken
h = httplib.HTTPConnection('www.thutreehole.tk')
b = {'csrfmiddlewaretoken':csrftoken,'content':words}
data = urllib.urlencode(b)
print opener.open("http://www.thutreehole.tk/",data).read()
def getPoem():
poems = open('./poems')
line = linecache.getline('./poems',random.randint(1,1500))
return '今天走在路上我突然想到了一句诗,不知道有没有男生能理解我此刻的心情:'+line+' 真想有个肩膀依靠啊....'
if __name__ == '__main__':
import time
while True:
poem = getPoem()
Say(poem)
time.sleep(1812)
@pantaovay
Copy link

LZ拙计

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment