Created
May 20, 2014 10:40
-
-
Save jk2K/6d50699feeacc80f7e80 to your computer and use it in GitHub Desktop.
自动将txt文本里的内容发布到fengche代办中
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from urllib import request | |
from urllib import parse | |
from http import cookiejar | |
username = 'your_username' | |
password = 'your_password' | |
login_url = 'https://fengcheco.com/auth/identity/callback' | |
project_id = 'your_project_id' | |
iteration_id = 'your_iteration_id' | |
def newticket(title): | |
data = parse.urlencode({ | |
'ticket[title]': title, | |
'ticket[iteration_id]': iteration_id, | |
'ticket[project_id]': project_id | |
}).encode('utf-8') | |
url = 'https://fengcheco.com/projects/' + project_id + '/tickets.json' | |
opener.open(url, data) | |
#登录获取cookie | |
cookie = cookiejar.CookieJar() | |
opener = request.build_opener(request.HTTPCookieProcessor(cookie)) | |
login_data = parse.urlencode({ | |
'utf8':'✓', | |
'auth_key': username, | |
'password': password, | |
'remember_me': '1' | |
}).encode('utf-8') | |
opener.open(login_url, login_data) | |
#循环处理文本 | |
with open('todo.txt', 'rb') as f: | |
lines = f.readlines() | |
for line in lines: | |
title = line.decode('utf-8') | |
print('processing ' + title) | |
newticket(title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment