Skip to content

Instantly share code, notes, and snippets.

View muzizongheng's full-sized avatar

muzizongheng(李建功) muzizongheng

View GitHub Profile
@muzizongheng
muzizongheng / AccessCSDN.py
Created July 18, 2013 06:01
create http get using cookie
#install cookie
cj = cookiejar.CookieJar();
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj));
urllib.request.install_opener(opener)
#build request for accessed url
homeReq = urllib.request.Request(
url = csdnAccessModuleUrl
)
@muzizongheng
muzizongheng / AccessCSDN.py
Created July 18, 2013 06:03
create http post by using Request
#build request for login url
#post data
postdata = {
'u':username,
'p':password,
'remember':'1',
't':'log',
'f':urllib.parse.quote(moduleUrl),
}
@muzizongheng
muzizongheng / AccessCSDN.py
Created July 18, 2013 06:04
read dict string and convert string to dict object
data = r.read().decode('utf-8')
reader = json.JSONDecoder()
responseData = reader.decode(data)
return responseData['data']
@muzizongheng
muzizongheng / AccessCSDN.py
Created July 18, 2013 06:04
define main function for python module file.
def main():
login_csdn()
url = new_post("title", "content", "categories", "tag2")
print(url)
if __name__ == "__main__":
main()
@muzizongheng
muzizongheng / AccessEN.py
Created July 18, 2013 06:53
convert file to dictionary
#read config
input_text = open('config', "r", encoding='utf-8-sig').read()
input_json = "{%(input_text)s}" % vars()
reader = json.JSONDecoder()
config = reader.decode(input_json)
@muzizongheng
muzizongheng / AccessEN.py
Created July 18, 2013 06:53
convert str to bool
self.isCreateTags = config["isCreateTags"] == str(True)
self.syncNotebook = config["syncNotebook"]
self.isUsingCSDNBlog = config["isUsingCSDNBlog"] == str(True)
@muzizongheng
muzizongheng / AccessEN.py
Created July 18, 2013 06:54
convert file to list
pingServiceUrls = open("pingcfg", "r", encoding='utf-8-sig')
pingServiceUrls.seek(0)
self.pingServiceUrls = pingServiceUrls.readlines()
print(self.pingServiceUrls)
@muzizongheng
muzizongheng / AccessEN.py
Created July 18, 2013 06:55
ping blog by url
#ping search engine's ping service
# http://ping.baidu.com/ping/RPC2
# http://rpc.pingomatic.com/
# http://api.moreover.com/ping
# http://api.my.yahoo.com/rss/ping
# http://blogsearch.google.com/ping/RPC2
# http://ping.bitacoras.com
# http://ping.feedburner.com
# http://ping.syndic8.com/xmlrpc.php
# http://rpc.blogrolling.com/pinger/
@muzizongheng
muzizongheng / Main.py
Created July 18, 2013 06:57
loop to get evernote's notes
# List all of the notebooks in the user's account
notebooks = noteStore.listNotebooks(authToken)
print("Found ", len(notebooks), " notebooks:")
#calculate processed blog count currently
processedBlogCount = 0
for notebook in notebooks:
print(" * ", notebook.name)
@muzizongheng
muzizongheng / Main.py
Created July 18, 2013 06:59
use md5 for file
#calculate hashcode for media
md5 = hashlib.md5()
md5.update(attachment.data.body)
hashcode = md5.hexdigest()
print("hast code: ", hashcode)