Changeset 71:c8e39db35e46 in stamper
- Timestamp:
- Sep 5, 2019, 4:38:38 PM (5 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
bin/stamp
r58 r71 3 3 import sys 4 4 from datetime import datetime 5 from stamper import Stamper5 from stamper.stamper import Stamper 6 6 7 7 -
bin/stamps
r61 r71 2 2 3 3 from stamper.cli import build_args_parser 4 from stamper import Stamper4 from stamper.stamper import Stamper 5 5 6 6 -
stamper/__init__.py
r58 r71 1 from stamper import Stamper 1 -
stamper/config.py
r58 r71 1 1 2 2 import os 3 from ConfigParser import SafeConfigParser3 from configparser import SafeConfigParser 4 4 5 5 -
stamper/http.py
r53 r71 1 1 2 from urllib2 import ( 3 Request, urlopen, build_opener, install_opener, HTTPCookieProcessor 4 ) 5 from urllib import urlencode 6 from urlparse import urljoin 2 import http.client 3 from urllib.parse import urlparse, urlencode, quote_plus 7 4 8 5 … … 10 7 11 8 def __init__(self, base_url): 12 self.base_url = base_url 13 self.request = build_opener(HTTPCookieProcessor()) 14 install_opener(self.request) 9 self.parsed_url = urlparse(base_url) 10 if self.parsed_url.scheme == 'https': 11 self.conn = http.client.HTTPSConnection(self.parsed_url.netloc) 12 else: 13 self.conn = http.client.HTTPConnection(self.parsed_url.netloc) 15 14 16 def send_request(self, url, data=None): 17 response = self.request.open(url, data) 15 def get(self, url): 16 self.conn.request('GET', url) 17 response = conn.getresponse() 18 18 return response.read() 19 19 20 def get(self, url):21 return self.send_request(urljoin(self.base_url, url))22 23 20 def post(self, url, data): 24 encoded_data = urlencode(data) 25 return self.send_request(urljoin(self.base_url, url), encoded_data) 21 encoded_data = urlencode(data, quote_via=quote_plus) 22 headers = {'Content-type': 'application/x-www-form-urlencoded', 23 'Accept': 'text/plain'} 24 self.conn.request('POST', url, encoded_data, headers) 25 response = conn.getresponse() 26 return response.read() -
stamper/stamper.py
r69 r71 292 292 # daily totals 293 293 print('daily total: %(total)s' % {'total': totals[day]}) 294 print '-'*79294 print('-'*79) 295 295 296 296 # now calculate the totals and show them … … 318 318 if totals: 319 319 print('------ Totals ------' % {'day': day}) 320 for day, tot in totals.ite ritems():320 for day, tot in totals.items(): 321 321 print(' %(day)s: %(total)s' % {'day': day, 'total': tot}) 322 322 sum_tot = "%(total)s %(new)s" % {
Note:
See TracChangeset
for help on using the changeset viewer.