[0] | 1 |
|
---|
| 2 | import json
|
---|
[43] | 3 | import os.path
|
---|
[63] | 4 | from datetime import datetime, timedelta
|
---|
[43] | 5 | from os import symlink, remove, makedirs
|
---|
[19] | 6 | from collections import OrderedDict
|
---|
[37] | 7 | from operator import itemgetter
|
---|
[43] | 8 | import pygal
|
---|
[0] | 9 |
|
---|
[56] | 10 | from .http import HTTPClient
|
---|
[58] | 11 | from .config import Config
|
---|
[63] | 12 | from .filters import DateFilter
|
---|
[0] | 13 |
|
---|
| 14 |
|
---|
[75] | 15 | def timedelta_to_hms(value):
|
---|
| 16 | """
|
---|
| 17 | Return hours, minutes, seconds from a timedelta object
|
---|
| 18 | """
|
---|
| 19 | hours, remainder = divmod(int(value.total_seconds()), 3600)
|
---|
| 20 | minutes, seconds = divmod(remainder, 60)
|
---|
| 21 | return hours, minutes, seconds
|
---|
| 22 |
|
---|
| 23 |
|
---|
[0] | 24 | class Stamper(object):
|
---|
| 25 |
|
---|
[58] | 26 | def __init__(self, config_file=None):
|
---|
| 27 | self.config = Config(config_file)
|
---|
| 28 | self.stamps_file = os.path.expanduser(
|
---|
| 29 | self.config.get('stamps', 'path'))
|
---|
| 30 | self.charts_dir = os.path.expanduser(
|
---|
| 31 | self.config.get('charts', 'path'))
|
---|
| 32 | self.date_format = self.config.get('stamps', 'date_format')
|
---|
| 33 | self.time_format = self.config.get('stamps', 'time_format')
|
---|
| 34 | self.datetime_format = self.config.get('stamps', 'datetime_format')
|
---|
[67] | 35 | self.wants_seconds = self.config.get('stamps', 'wants_seconds')
|
---|
[58] | 36 | self.hours_day = int(self.config.get('sum', 'hours_day'))
|
---|
| 37 | self.collector = self.config.get('collector')
|
---|
[0] | 38 | self.ensure_stamps_file()
|
---|
[43] | 39 | self.ensure_charts_dir()
|
---|
[0] | 40 | self.stamps = []
|
---|
[63] | 41 | self.date_filter = DateFilter(self.date_format)
|
---|
[0] | 42 |
|
---|
[37] | 43 | def __json_load(self, filename):
|
---|
| 44 | """
|
---|
| 45 | Load the stamps from a file in json format, returning
|
---|
| 46 | the parsed list.
|
---|
| 47 | """
|
---|
| 48 | with open(filename, 'r') as stamps_file:
|
---|
| 49 | try:
|
---|
| 50 | stamps = json.load(stamps_file)
|
---|
| 51 | except ValueError:
|
---|
| 52 | stamps = []
|
---|
| 53 | return stamps
|
---|
| 54 |
|
---|
| 55 | def remove_duplicates(self):
|
---|
| 56 | """
|
---|
| 57 | Remove duplicated stamps from the stamps list
|
---|
| 58 | """
|
---|
| 59 | stamps = [dict(t) for t in set(
|
---|
| 60 | [tuple(d.items()) for d in self.stamps])]
|
---|
| 61 | self.stamps = stamps
|
---|
| 62 |
|
---|
[0] | 63 | def ensure_stamps_file(self):
|
---|
[43] | 64 | if not os.path.exists(self.stamps_file):
|
---|
[0] | 65 | with open(self.stamps_file, 'w') as stamps_file:
|
---|
| 66 | stamps_file.write('')
|
---|
| 67 |
|
---|
[43] | 68 | def ensure_charts_dir(self):
|
---|
| 69 | if not os.path.exists(self.charts_dir):
|
---|
| 70 | makedirs(self.charts_dir)
|
---|
| 71 |
|
---|
[0] | 72 | def load_stamps(self):
|
---|
[37] | 73 | self.stamps = self.__json_load(self.stamps_file)
|
---|
| 74 |
|
---|
| 75 | def sort_stamps(self):
|
---|
| 76 | """
|
---|
| 77 | Sort all the stamps by start and end dates
|
---|
| 78 | """
|
---|
| 79 | self.stamps = sorted(self.stamps, key=itemgetter('start', 'end'))
|
---|
[0] | 80 |
|
---|
| 81 | def save_stamps(self):
|
---|
| 82 | with open(self.stamps_file, 'w') as stamps_file:
|
---|
| 83 | json.dump(self.stamps, stamps_file, indent=4)
|
---|
| 84 |
|
---|
| 85 | def stamp(self, start, end, customer, action):
|
---|
| 86 | self.stamps.append({
|
---|
| 87 | 'start': start,
|
---|
| 88 | 'end': end,
|
---|
| 89 | 'customer': customer,
|
---|
| 90 | 'action': action,
|
---|
| 91 | })
|
---|
| 92 |
|
---|
[32] | 93 | def last_stamp(self, n=1):
|
---|
| 94 | """
|
---|
| 95 | return the stamp in position -n, that is, starting from the latest one
|
---|
| 96 | and going back N positions in the list of stamps
|
---|
| 97 | """
|
---|
[0] | 98 | if not self.stamps:
|
---|
| 99 | return None
|
---|
[32] | 100 | return self.stamps[-n]
|
---|
[0] | 101 |
|
---|
| 102 | def worktime(self, start, end):
|
---|
[58] | 103 | worktime = (datetime.strptime(end, self.datetime_format) -
|
---|
| 104 | datetime.strptime(start, self.datetime_format))
|
---|
[0] | 105 | return worktime.seconds
|
---|
| 106 |
|
---|
[30] | 107 | @property
|
---|
[0] | 108 | def customers(self):
|
---|
| 109 | customers = []
|
---|
| 110 | for stamp in self.stamps:
|
---|
| 111 | if stamp['customer'] not in customers:
|
---|
| 112 | customers.append(stamp['customer'])
|
---|
| 113 | customers.remove(None)
|
---|
| 114 | return customers
|
---|
| 115 |
|
---|
[61] | 116 | def totals(self, filter_from=None, filter_to=None, filter_descr=None):
|
---|
[8] | 117 | totals = {}
|
---|
| 118 | for stamp in self.stamps:
|
---|
| 119 | customer = stamp['customer']
|
---|
[26] | 120 | # customer will be None for "start" stamps, having no end time
|
---|
[8] | 121 | if customer:
|
---|
[58] | 122 | start = datetime.strptime(stamp['start'], self.datetime_format)
|
---|
| 123 | end = datetime.strptime(stamp['end'], self.datetime_format)
|
---|
[26] | 124 | if filter_from and start < filter_from:
|
---|
| 125 | # if there is a filter setting a starting date for the
|
---|
| 126 | # report and the current stamp is from an earlier date, do
|
---|
| 127 | # not add it to the totals
|
---|
| 128 | continue
|
---|
| 129 | if filter_to and start > filter_to:
|
---|
| 130 | # similar for the end date
|
---|
| 131 | continue
|
---|
[61] | 132 | if filter_descr and filter_descr not in stamp['action']:
|
---|
| 133 | continue
|
---|
[8] | 134 | if customer not in totals:
|
---|
| 135 | totals[customer] = 0
|
---|
| 136 | totals[customer] += self.worktime(stamp['start'], stamp['end'])
|
---|
| 137 | return totals
|
---|
| 138 |
|
---|
[61] | 139 | def details(self, filter_customer=None, filter_from=None, filter_to=None,
|
---|
| 140 | filter_descr=None):
|
---|
[19] | 141 | details = OrderedDict()
|
---|
| 142 | totals = OrderedDict()
|
---|
[23] | 143 | total_customer = OrderedDict()
|
---|
[0] | 144 | for stamp in self.stamps:
|
---|
[26] | 145 | customer = stamp['customer']
|
---|
| 146 | if customer:
|
---|
| 147 | if filter_customer and customer != filter_customer:
|
---|
| 148 | # we are getting the details for only one customer, if this
|
---|
| 149 | # stamp is not for that customer, simply move on and ignore
|
---|
| 150 | # it
|
---|
| 151 | continue
|
---|
[58] | 152 | start = datetime.strptime(stamp['start'], self.datetime_format)
|
---|
[26] | 153 | start_day = start.strftime('%Y-%m-%d')
|
---|
[58] | 154 | end = datetime.strptime(stamp['end'], self.datetime_format)
|
---|
[26] | 155 | if filter_from and start < filter_from:
|
---|
| 156 | # if there is a filter setting a starting date for the
|
---|
| 157 | # report and the current stamp is from an earlier date, do
|
---|
| 158 | # not add it to the totals
|
---|
| 159 | continue
|
---|
| 160 | if filter_to and start > filter_to:
|
---|
| 161 | # similar for the end date
|
---|
| 162 | continue
|
---|
[61] | 163 | if filter_descr and filter_descr not in stamp['action']:
|
---|
| 164 | continue
|
---|
[8] | 165 | # avoid "start" stamps
|
---|
| 166 | if start_day not in details:
|
---|
| 167 | details[start_day] = []
|
---|
| 168 | if start_day not in totals:
|
---|
| 169 | totals[start_day] = 0
|
---|
| 170 | worktime = self.worktime(stamp['start'], stamp['end'])
|
---|
[67] | 171 | str_worktime = str(timedelta(seconds=worktime))
|
---|
| 172 | if not self.wants_seconds or self.wants_seconds == 'false':
|
---|
| 173 | # remove the seconds part from the string representation
|
---|
| 174 | str_worktime = ':'.join(str_worktime.split(':')[:-1])
|
---|
[8] | 175 | details[start_day].append(
|
---|
[39] | 176 | '%(worktime)s %(customer)s %(action)s' % {
|
---|
[67] | 177 | 'worktime': str_worktime,
|
---|
[26] | 178 | 'customer': customer,
|
---|
[8] | 179 | 'action': stamp['action']
|
---|
| 180 | })
|
---|
| 181 | totals[start_day] += worktime
|
---|
[23] | 182 | if start_day not in total_customer:
|
---|
| 183 | total_customer[start_day] = {}
|
---|
| 184 | if customer not in total_customer[start_day]:
|
---|
| 185 | total_customer[start_day][customer] = 0
|
---|
| 186 | total_customer[start_day][customer] += worktime
|
---|
[8] | 187 | for day in totals:
|
---|
| 188 | totals[day] = str(timedelta(seconds=totals[day]))
|
---|
[67] | 189 | if not self.wants_seconds or self.wants_seconds == 'false':
|
---|
| 190 | # remove the seconds part from the string representation
|
---|
| 191 | totals[day] = ':'.join(totals[day].split(':')[:-1])
|
---|
[23] | 192 | return details, totals, total_customer
|
---|
[0] | 193 |
|
---|
[61] | 194 | def timeline(self, customer=None, stamp_filter=None, filter_descr=None):
|
---|
[63] | 195 | filter_from, filter_to = self.date_filter.validate(stamp_filter)
|
---|
[28] | 196 | for stamp in self.stamps:
|
---|
[58] | 197 | start = datetime.strptime(stamp['start'], self.datetime_format)
|
---|
[38] | 198 | start_day = start.strftime('%Y-%m-%d')
|
---|
| 199 | if filter_from and start < filter_from:
|
---|
| 200 | # if there is a filter setting a starting date for the
|
---|
| 201 | # report and the current stamp is from an earlier date, do
|
---|
| 202 | # not add it to the totals
|
---|
| 203 | continue
|
---|
| 204 | if filter_to and start > filter_to:
|
---|
| 205 | # similar for the end date
|
---|
| 206 | continue
|
---|
[61] | 207 | if filter_descr and stamp['action']:
|
---|
| 208 | if filter_descr not in stamp['action']:
|
---|
| 209 | continue
|
---|
[28] | 210 | if not stamp['customer']:
|
---|
[40] | 211 | if customer is None:
|
---|
| 212 | print(stamp['start'] + ' start')
|
---|
[28] | 213 | else:
|
---|
[40] | 214 | if customer and customer != stamp['customer']:
|
---|
| 215 | continue
|
---|
| 216 | if customer:
|
---|
| 217 | print(stamp['start'] + ' start')
|
---|
[28] | 218 | print(' '.join([stamp['end'],
|
---|
| 219 | stamp['customer'],
|
---|
| 220 | stamp['action']]))
|
---|
| 221 |
|
---|
[61] | 222 | def graph_stamps(self, customer=None, stamp_filter=None, filter_descr=None):
|
---|
[30] | 223 | """
|
---|
| 224 | Generate charts with information from the stamps
|
---|
| 225 | """
|
---|
[63] | 226 | filter_from, filter_to = self.date_filter.validate(stamp_filter)
|
---|
[30] | 227 | chart = pygal.Bar(title='Work hours per day',
|
---|
[58] | 228 | range=(0, self.hours_day),
|
---|
[30] | 229 | x_title='Days',
|
---|
| 230 | y_title='Work hours',
|
---|
| 231 | x_label_rotation=45)
|
---|
| 232 |
|
---|
| 233 | details, totals, totals_customers = self.details(customer,
|
---|
| 234 | filter_from,
|
---|
[61] | 235 | filter_to,
|
---|
| 236 | filter_descr)
|
---|
[30] | 237 | days = []
|
---|
| 238 | values = {}
|
---|
| 239 | for c in self.customers:
|
---|
| 240 | values[c] = []
|
---|
| 241 |
|
---|
| 242 | found = []
|
---|
| 243 |
|
---|
| 244 | for day in details:
|
---|
| 245 | for c in values:
|
---|
| 246 | seconds = totals_customers[day].get(c, 0)
|
---|
| 247 | if seconds and c not in found:
|
---|
| 248 | found.append(c)
|
---|
| 249 | human = timedelta(seconds=seconds).__str__()
|
---|
| 250 | values[c].append({'value': seconds/60.00/60.00,
|
---|
| 251 | 'label': day + ': ' + human})
|
---|
| 252 | days.append(day)
|
---|
| 253 | chart.x_labels = map(str, days)
|
---|
| 254 |
|
---|
| 255 | if customer:
|
---|
| 256 | chart.add(customer, values[customer])
|
---|
| 257 | else:
|
---|
| 258 | for c in found:
|
---|
| 259 | chart.add(c, values[c])
|
---|
| 260 |
|
---|
| 261 | chart_name = 'chart-%s.svg' % datetime.today().strftime(
|
---|
| 262 | '%Y-%m-%d_%H%M%S')
|
---|
| 263 | chart_symlink = 'chart-latest.svg'
|
---|
[43] | 264 | chart_path = os.path.join(self.charts_dir, chart_name)
|
---|
| 265 | chart_symlink_path = os.path.join(self.charts_dir, chart_symlink)
|
---|
| 266 |
|
---|
| 267 | chart.render_to_file(chart_path)
|
---|
| 268 | print('Rendered chart: ' + chart_path)
|
---|
| 269 | if os.path.islink(chart_symlink_path):
|
---|
| 270 | remove(chart_symlink_path)
|
---|
| 271 | symlink(chart_name, chart_symlink_path)
|
---|
| 272 | print('Updated latest chart: ' + chart_symlink_path)
|
---|
[30] | 273 |
|
---|
[22] | 274 | def show_stamps(self, customer=None, stamp_filter=None, verbose=False,
|
---|
[61] | 275 | sum=False, filter_descr=None):
|
---|
[63] | 276 | filter_from, filter_to = self.date_filter.validate(stamp_filter)
|
---|
[9] | 277 |
|
---|
[26] | 278 | # If the user asks for verbose information, show it before the
|
---|
| 279 | # totals (mimicing what the original stamp tool does)
|
---|
| 280 | if verbose:
|
---|
| 281 | details, totals, total_customer = self.details(customer,
|
---|
| 282 | filter_from,
|
---|
[61] | 283 | filter_to,
|
---|
| 284 | filter_descr)
|
---|
[26] | 285 | for day in details:
|
---|
| 286 | print('------ %(day)s ------' % {'day': day})
|
---|
| 287 | for line in details[day]:
|
---|
| 288 | print(line)
|
---|
[39] | 289 | customer_day_totals = []
|
---|
| 290 | for tc in total_customer[day]:
|
---|
| 291 | tc_total = str(timedelta(seconds=total_customer[day][tc]))
|
---|
[67] | 292 | if not self.wants_seconds or self.wants_seconds == 'false':
|
---|
| 293 | # remove the seconds part from the string representation
|
---|
| 294 | tc_total = ':'.join(tc_total.split(':')[:-1])
|
---|
[69] | 295 | # ensure hours show double digits
|
---|
| 296 | tc_total = tc_total.zfill(5)
|
---|
[39] | 297 | customer_day_totals.append(tc+': '+tc_total)
|
---|
| 298 | print(', '.join(customer_day_totals))
|
---|
| 299 | if len(customer_day_totals) > 1:
|
---|
| 300 | # if there are multiple customers in the report, show the
|
---|
| 301 | # daily totals
|
---|
| 302 | print('daily total: %(total)s' % {'total': totals[day]})
|
---|
[71] | 303 | print('-'*79)
|
---|
[9] | 304 |
|
---|
[26] | 305 | # now calculate the totals and show them
|
---|
[61] | 306 | totals = self.totals(filter_from, filter_to, filter_descr)
|
---|
[9] | 307 | if customer:
|
---|
[22] | 308 | seconds=totals.get(customer, 0)
|
---|
[23] | 309 | total = timedelta(seconds=totals.get(customer, 0))
|
---|
[75] | 310 | h, m, s = timedelta_to_hms(total)
|
---|
| 311 | total = ':'.join(
|
---|
| 312 | [str(h).zfill(2), str(m).zfill(2), str(s).zfill(2)])
|
---|
[67] | 313 | if not self.wants_seconds or self.wants_seconds == 'false':
|
---|
| 314 | # remove the seconds part from the string representation
|
---|
| 315 | total = ':'.join(str(total).split(':')[:-1])
|
---|
[9] | 316 | print(' %(customer)s: %(total)s' % {'customer': customer,
|
---|
| 317 | 'total': total})
|
---|
| 318 | else:
|
---|
| 319 | for c in totals:
|
---|
[22] | 320 | seconds=totals[c]
|
---|
[23] | 321 | total = timedelta(seconds=totals[c])
|
---|
[75] | 322 | h, m, s = timedelta_to_hms(total)
|
---|
| 323 | total = ':'.join(
|
---|
| 324 | [str(h).zfill(2), str(m).zfill(2), str(s).zfill(2)])
|
---|
[67] | 325 | if not self.wants_seconds or self.wants_seconds == 'false':
|
---|
| 326 | # remove the seconds part from the string representation
|
---|
| 327 | total = ':'.join(str(total).split(':')[:-1])
|
---|
[9] | 328 | print(' %(customer)s: %(total)s' % {'customer': c,
|
---|
| 329 | 'total': total})
|
---|
| 330 |
|
---|
[22] | 331 | if sum:
|
---|
| 332 | sum_tot = ''
|
---|
| 333 | if totals:
|
---|
| 334 | print('------ Totals ------' % {'day': day})
|
---|
[71] | 335 | for day, tot in totals.items():
|
---|
[22] | 336 | print(' %(day)s: %(total)s' % {'day': day, 'total': tot})
|
---|
| 337 | sum_tot = "%(total)s %(new)s" % {
|
---|
| 338 | 'total': sum_tot,
|
---|
| 339 | 'new': total
|
---|
| 340 | }
|
---|
| 341 | totalSecs, sec = divmod(seconds, 60)
|
---|
| 342 | hr, min = divmod(totalSecs, 60)
|
---|
[58] | 343 | totalDays, remaining = divmod(seconds,
|
---|
| 344 | (self.hours_day * 60 * 60))
|
---|
[22] | 345 | remainingMin, remainingSec = divmod(remaining, (60))
|
---|
| 346 | remainingHr, remainingMin = divmod(remainingMin, (60))
|
---|
| 347 | print('----- %d:%02d:%02d -----' % (hr, min, sec))
|
---|
| 348 | print('--- %d days, remaining: %d:%02d (%d hours/day) ---' % (
|
---|
[58] | 349 | totalDays, remainingHr, remainingMin, self.hours_day
|
---|
[22] | 350 | ))
|
---|
[32] | 351 |
|
---|
| 352 | def remove_stamps(self, n=1):
|
---|
| 353 | """
|
---|
| 354 | Remove up to n stamps back, asking for confirmation before delete
|
---|
| 355 | """
|
---|
| 356 | for i in range(n):
|
---|
| 357 | stamp = self.last_stamp()
|
---|
| 358 | if not stamp['customer']:
|
---|
| 359 | print(stamp['start'] + ' start')
|
---|
| 360 | else:
|
---|
| 361 | print(' '.join([stamp['end'],
|
---|
| 362 | stamp['customer'],
|
---|
| 363 | stamp['action']]))
|
---|
| 364 | confirm = ''
|
---|
| 365 | while confirm.lower() not in ['y', 'n']:
|
---|
[74] | 366 | confirm = input('delete stamp? (y/n) ')
|
---|
[32] | 367 | confirm = confirm.lower()
|
---|
| 368 | if confirm == 'y':
|
---|
| 369 | self.stamps.pop()
|
---|
| 370 | else:
|
---|
| 371 | # if the user says no to the removal of an stamp, we cannot
|
---|
| 372 | # keep deleting stamps after that one, as that could leave the
|
---|
| 373 | # stamps in an inconsistent state.
|
---|
| 374 | print('Aborting removal of stamps')
|
---|
| 375 | break
|
---|
| 376 | self.save_stamps()
|
---|
[37] | 377 |
|
---|
| 378 | def import_stamps(self, filename):
|
---|
| 379 | """
|
---|
| 380 | Import the stamps from the given file into the main stamps list,
|
---|
| 381 | merging them into the list (removing duplicated entries)
|
---|
| 382 | """
|
---|
[43] | 383 | if not os.path.exists(filename):
|
---|
[37] | 384 | print('[error] ' + filename + 'does not exist')
|
---|
| 385 | return
|
---|
[43] | 386 | if os.path.isdir(filename):
|
---|
[37] | 387 | print('[error] ' + filename + 'is a directory')
|
---|
| 388 | return
|
---|
| 389 | stamps = self.__json_load(filename)
|
---|
| 390 | if not stamps:
|
---|
| 391 | print('[warning] no stamps can be imported from ' + filename)
|
---|
| 392 | return
|
---|
| 393 | self.stamps.extend(stamps)
|
---|
| 394 | self.remove_duplicates()
|
---|
| 395 | self.sort_stamps()
|
---|
| 396 | self.save_stamps()
|
---|
| 397 | print('[warning] ' + str(len(stamps)) + ' stamps merged')
|
---|
| 398 | print('[warning] remember to review the resulting stamps file')
|
---|
[52] | 399 |
|
---|
[61] | 400 | def push_stamps(self, customer=None, stamp_filter=None, filter_descr=None):
|
---|
[63] | 401 | filter_from, filter_to = self.date_filter.validate(stamp_filter)
|
---|
[54] | 402 |
|
---|
[52] | 403 | stamps = []
|
---|
| 404 | for stamp in self.stamps:
|
---|
| 405 | if stamp['customer']:
|
---|
| 406 | if customer and customer != stamp['customer']:
|
---|
| 407 | continue
|
---|
[58] | 408 | start = datetime.strptime(stamp['start'], self.datetime_format)
|
---|
[52] | 409 | start_day = start.strftime('%Y-%m-%d')
|
---|
[58] | 410 | end = datetime.strptime(stamp['end'], self.datetime_format)
|
---|
[52] | 411 | if filter_from and start < filter_from:
|
---|
| 412 | # if there is a filter setting a starting date for the
|
---|
| 413 | # report and the current stamp is from an earlier date, do
|
---|
| 414 | # not add it to the totals
|
---|
| 415 | continue
|
---|
| 416 | if filter_to and start > filter_to:
|
---|
| 417 | # similar for the end date
|
---|
| 418 | continue
|
---|
[61] | 419 | if filter_descr and filter_descr not in stamp['action']:
|
---|
| 420 | continue
|
---|
[52] | 421 | stamps.append(stamp)
|
---|
[54] | 422 |
|
---|
[52] | 423 | stamps = json.dumps(stamps, indent=4)
|
---|
[58] | 424 | http_client = HTTPClient(self.collector['base_url'])
|
---|
[60] | 425 | response = http_client.post(self.collector['login_path'],
|
---|
| 426 | {'username': self.collector['user'],
|
---|
| 427 | 'password': self.collector['password']})
|
---|
| 428 | # response is a json-encoded list of end-points from the collector api
|
---|
| 429 | try:
|
---|
| 430 | api = json.loads(response)
|
---|
| 431 | except ValueError:
|
---|
| 432 | print('[error] No valid api end points can be retrieved')
|
---|
| 433 | return
|
---|
| 434 |
|
---|
| 435 | response = http_client.post(api['push'], {'stamps': stamps})
|
---|
| 436 |
|
---|
| 437 | # response is a json-encoded dict, containing lists of added, updated
|
---|
| 438 | # and deleted stamps (on the other side)
|
---|
| 439 | try:
|
---|
| 440 | results = json.loads(response)
|
---|
| 441 | except ValueError:
|
---|
| 442 | print('[error] stamps pushed, can not retrieve results information')
|
---|
| 443 | return
|
---|
| 444 |
|
---|
| 445 | # display information
|
---|
| 446 | for k in results.keys():
|
---|
| 447 | print('%(stamps)d stamps %(action)s' % {'stamps': len(results[k]),
|
---|
| 448 | 'action': k})
|
---|