Skip to content

Commit

Permalink
beautify code
Browse files Browse the repository at this point in the history
  • Loading branch information
zeruniverse committed Aug 18, 2015
1 parent 7eefc45 commit dfad5bf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
71 changes: 36 additions & 35 deletions HttpClient.py
@@ -1,48 +1,49 @@
# HttpClient.py is written by [xqin]: https://github.com/xqin/SmartQQ-for-Raspberry-Pi
import cookielib, urllib, urllib2

class HttpClient:
__cookie = cookielib.CookieJar()
__req = urllib2.build_opener(urllib2.HTTPCookieProcessor(__cookie))
__req.addheaders = [
('Accept', 'application/javascript, */*;q=0.8'),
('User-Agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)')
]
urllib2.install_opener(__req)
__cookie = cookielib.CookieJar()
__req = urllib2.build_opener(urllib2.HTTPCookieProcessor(__cookie))
__req.addheaders = [
('Accept', 'application/javascript, */*;q=0.8'),
('User-Agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)')
]
urllib2.install_opener(__req)

def Get(self, url, refer=None):
try:
req = urllib2.Request(url)
if not (refer is None):
req.add_header('Referer', refer)
return urllib2.urlopen(req).read()
except urllib2.HTTPError, e:
return e.read()
def Get(self, url, refer=None):
try:
req = urllib2.Request(url)
if not (refer is None):
req.add_header('Referer', refer)
return urllib2.urlopen(req).read()
except urllib2.HTTPError, e:
return e.read()

def Post(self, url, data, refer=None):
try:
req = urllib2.Request(url, urllib.urlencode(data))
if not (refer is None):
req.add_header('Referer', refer)
return urllib2.urlopen(req).read()
except urllib2.HTTPError, e:
return e.read()
def Post(self, url, data, refer=None):
try:
req = urllib2.Request(url, urllib.urlencode(data))
if not (refer is None):
req.add_header('Referer', refer)
return urllib2.urlopen(req).read()
except urllib2.HTTPError, e:
return e.read()

def Download(self, url, file):
output = open(file, 'wb')
output.write(urllib2.urlopen(url).read())
output.close()
def Download(self, url, file):
output = open(file, 'wb')
output.write(urllib2.urlopen(url).read())
output.close()

# def urlencode(self, data):
# return urllib.quote(data)

def getCookie(self, key):
for c in self.__cookie:
if c.name == key:
return c.value
return ''
def getCookie(self, key):
for c in self.__cookie:
if c.name == key:
return c.value
return ''

def setCookie(self, key, val, domain):
ck = cookielib.Cookie(version=0, name=key, value=val, port=None, port_specified=False, domain=domain, domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
self.__cookie.set_cookie(ck)
def setCookie(self, key, val, domain):
ck = cookielib.Cookie(version=0, name=key, value=val, port=None, port_specified=False, domain=domain, domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
self.__cookie.set_cookie(ck)
#self.__cookie.clear() clean cookie
# vim : tabstop=2 shiftwidth=2 softtabstop=2 expandtab
18 changes: 15 additions & 3 deletions LICENSE
@@ -1,3 +1,14 @@
All files in this software are licensed under GNU GPL 3.0
HttpClient.py is written by [xqin]: https://github.com/xqin/SmartQQ-for-Raspberry-Pi
All other files are written by [Jeffery]: https://github.com/zeruniverse/QQRobot
The implementation of SmartQQ Message handler and part of group chatting logic are from [Yinzo]: https://github.com/Yinzo/SmartQQBot
All source codes I referred to are licensed under GNU GPL 3.0 or compatible to GNU GPL 3.0

- Jeffery Zhao
Below is the GNU GPL 3.0 License

------------------------------------------------------------------------------------------------------------------------------------

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Expand Down Expand Up @@ -631,8 +642,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -652,7 +663,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

<program> Copyright (C) <year> <name of author>
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand All @@ -672,3 +683,4 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

0 comments on commit dfad5bf

Please sign in to comment.