David Blume commited on 2018-01-21 15:53:13
Showing 2 changed files, with 16 additions and 33 deletions.
| ... | ... |
@@ -33,7 +33,7 @@ def unique(seq, idfun=None): |
| 33 | 33 |
return result |
| 34 | 34 |
|
| 35 | 35 |
|
| 36 |
-def Process_comments_for_feed(yaml_items): |
|
| 36 |
+def process_comments_for_feed(yaml_items): |
|
| 37 | 37 |
time_blocks = [[], [], [], [], [], [], [], []] |
| 38 | 38 |
for i in yaml_items: |
| 39 | 39 |
time_posted = i['orig_posted'] |
| ... | ... |
@@ -55,7 +55,7 @@ def Process_comments_for_feed(yaml_items): |
| 55 | 55 |
return stats |
| 56 | 56 |
|
| 57 | 57 |
|
| 58 |
-def Remove_outliers(time_blocks): |
|
| 58 |
+def remove_outliers(time_blocks): |
|
| 59 | 59 |
"""remove 6% of the values as outliers (3% from each side).""" |
| 60 | 60 |
for block in time_blocks: |
| 61 | 61 |
pairs_to_remove = 0 |
| ... | ... |
@@ -70,7 +70,7 @@ def Remove_outliers(time_blocks): |
| 70 | 70 |
pairs_to_remove -= 1 |
| 71 | 71 |
|
| 72 | 72 |
|
| 73 |
-def Calculate_median_mean_stddev(time_blocks): |
|
| 73 |
+def calculate_median_mean_stddev(time_blocks): |
|
| 74 | 74 |
stats = [] |
| 75 | 75 |
for block in time_blocks: |
| 76 | 76 |
# Calculate the median |
| ... | ... |
@@ -94,7 +94,7 @@ def Calculate_median_mean_stddev(time_blocks): |
| 94 | 94 |
return stats |
| 95 | 95 |
|
| 96 | 96 |
|
| 97 |
-def Process_feed(yaml_items, metric, metric_times): |
|
| 97 |
+def process_feed(yaml_items, metric, metric_times): |
|
| 98 | 98 |
weekend_time_blocks = [[], [], [], [], [], [], [], []] |
| 99 | 99 |
weekday_time_blocks = [[], [], [], [], [], [], [], []] |
| 100 | 100 |
for i in yaml_items: |
| ... | ... |
@@ -111,11 +111,11 @@ def Process_feed(yaml_items, metric, metric_times): |
| 111 | 111 |
else: |
| 112 | 112 |
bisect.insort(weekday_time_blocks[value_times_indices[j]], values[j]) |
| 113 | 113 |
|
| 114 |
- Remove_outliers(weekend_time_blocks) |
|
| 115 |
- Remove_outliers(weekday_time_blocks) |
|
| 114 |
+ remove_outliers(weekend_time_blocks) |
|
| 115 |
+ remove_outliers(weekday_time_blocks) |
|
| 116 | 116 |
|
| 117 |
- weekend_stats = Calculate_median_mean_stddev(weekend_time_blocks) |
|
| 118 |
- weekday_stats = Calculate_median_mean_stddev(weekday_time_blocks) |
|
| 117 |
+ weekend_stats = calculate_median_mean_stddev(weekend_time_blocks) |
|
| 118 |
+ weekday_stats = calculate_median_mean_stddev(weekday_time_blocks) |
|
| 119 | 119 |
|
| 120 | 120 |
return weekend_stats, weekday_stats |
| 121 | 121 |
|
| ... | ... |
@@ -31,7 +31,7 @@ import smtp_creds # Your own credentials, used in send_email() |
| 31 | 31 |
|
| 32 | 32 |
debug = True |
| 33 | 33 |
any_entry_added = False |
| 34 |
-tags_to_post = set(['apple', 'google']) |
|
| 34 |
+tags_to_post = {'apple', 'google'}
|
|
| 35 | 35 |
authors_to_post = ['michael arrington',] |
| 36 | 36 |
|
| 37 | 37 |
# TODO 2018-01-18: Maybe combine fb_likes with bf_shares or something... |
| ... | ... |
@@ -92,9 +92,9 @@ odd_watermark = "D0D0F0" |
| 92 | 92 |
def asciiize(s): |
| 93 | 93 |
try: |
| 94 | 94 |
return s.encode('ascii')
|
| 95 |
- except UnicodeEncodeError as e: |
|
| 95 |
+ except UnicodeEncodeError: |
|
| 96 | 96 |
return s |
| 97 |
- except exceptions.AttributeError as e: |
|
| 97 |
+ except exceptions.AttributeError: |
|
| 98 | 98 |
return s |
| 99 | 99 |
|
| 100 | 100 |
|
| ... | ... |
@@ -103,8 +103,8 @@ def send_email(subject, message, toaddrs, |
| 103 | 103 |
""" Sends Email """ |
| 104 | 104 |
smtp = smtplib.SMTP(smtp_creds.server, port=smtp_creds.port) |
| 105 | 105 |
smtp.login(smtp_creds.user, smtp_creds.passw) |
| 106 |
- smtp.sendmail(fromaddr, \ |
|
| 107 |
- toaddrs, \ |
|
| 106 |
+ smtp.sendmail(fromaddr, |
|
| 107 |
+ toaddrs, |
|
| 108 | 108 |
"Content-Type: text/plain; charset=\"us-ascii\"\r\nFrom: %s\r\nTo: %s\r\nSubject: %s\r\n%s" % \ |
| 109 | 109 |
(fromaddr, ", ".join(toaddrs), subject, message)) |
| 110 | 110 |
smtp.quit() |
| ... | ... |
@@ -134,13 +134,9 @@ def make_chart_url(time_posted, lhs_times, lhs_values, rhs_times, |
| 134 | 134 |
lhs_times = [(i - time_posted) / 1800 for i in lhs_times] |
| 135 | 135 |
rhs_times = [(i - time_posted) / 1800 for i in rhs_times] |
| 136 | 136 |
|
| 137 |
- min_comment_time = min(lhs_times) |
|
| 138 | 137 |
max_comment_time = max(lhs_times) |
| 139 |
- min_comment_value = min(lhs_values) |
|
| 140 | 138 |
max_comment_value = max(lhs_values) |
| 141 |
- min_rhs_time = min(rhs_times) |
|
| 142 | 139 |
max_rhs_time = max(rhs_times) |
| 143 |
- min_rhs_value = min(rhs_values) |
|
| 144 | 140 |
max_rhs_value = max(rhs_values) |
| 145 | 141 |
|
| 146 | 142 |
met_threshold_pt = -1 |
| ... | ... |
@@ -213,7 +209,6 @@ def process_feed(yaml_items): |
| 213 | 209 |
if feed.status == 304: |
| 214 | 210 |
pass |
| 215 | 211 |
else: |
| 216 |
- feed_is_modified = True |
|
| 217 | 212 |
if feed.status != 200 and feed.status != 307 and feed.status != 301 and feed.status != 302: |
| 218 | 213 |
if feed.status == 503: |
| 219 | 214 |
print "the feed is temporarily unavailable." |
| ... | ... |
@@ -242,7 +237,6 @@ def process_feed(yaml_items): |
| 242 | 237 |
(# str(e.__class__), |
| 243 | 238 |
str(e)) |
| 244 | 239 |
traceback.print_exc(3, file=sys.stdout) |
| 245 |
- feed_is_modified = False |
|
| 246 | 240 |
|
| 247 | 241 |
for i in reversed(feed.entries): |
| 248 | 242 |
process_item(i, yaml_items) |
| ... | ... |
@@ -295,10 +289,8 @@ def process_item(feed_item, yaml_items): |
| 295 | 289 |
date_parsed = time.gmtime() |
| 296 | 290 |
if hasattr(feed_item, 'issued_parsed'): |
| 297 | 291 |
date_parsed = feed_item.issued_parsed |
| 298 |
- date_set = True |
|
| 299 | 292 |
elif hasattr(feed_item, 'date_parsed'): |
| 300 | 293 |
date_parsed = feed_item.date_parsed |
| 301 |
- date_set = True |
|
| 302 | 294 |
else: |
| 303 | 295 |
print "process_item found no timestamp for", asciiize(feed_item.link) |
| 304 | 296 |
timecode_parsed = calendar.timegm(date_parsed) |
| ... | ... |
@@ -376,14 +368,14 @@ def process_yaml_item(yaml_item): |
| 376 | 368 |
yaml_item['fb_likes'].append(num_likes) |
| 377 | 369 |
|
| 378 | 370 |
# if len(yaml_item['reddit_']) < 8: |
| 379 |
-# num_ = Get_reddit_stats(link) |
|
| 371 |
+# num_ = get_reddit_stats(link) |
|
| 380 | 372 |
# if num_ != -1: |
| 381 | 373 |
# any_entry_added = True |
| 382 | 374 |
# yaml_item['reddit_times'].append(timecode_now) |
| 383 | 375 |
# yaml_item['reddit_'].append(num_) |
| 384 | 376 |
|
| 385 | 377 |
|
| 386 |
-def Get_reddit_stats(url_string): |
|
| 378 |
+def get_reddit_stats(url_string): |
|
| 387 | 379 |
""" Consider curl "https://www.reddit.com/api/info.json?url=http://i.imgur.com/HG9dJ.jpg" |
| 388 | 380 |
""" |
| 389 | 381 |
return -1 |
| ... | ... |
@@ -414,15 +406,6 @@ def Get_fb_stats(url_string): |
| 414 | 406 |
else: |
| 415 | 407 |
print "Get_fb_stats got an error (3):", str(e) |
| 416 | 408 |
return shares, comments, likes |
| 417 |
- except KeyError as e: |
|
| 418 |
- print "Get_fb_stats got a key error 1e (%s)" % (str(e), ) |
|
| 419 |
- print "Get_fb_stats got a key error 2.2 enc (%s)" % (encoded, ) |
|
| 420 |
- print url_string.encode('utf-8')
|
|
| 421 |
- print u"Get_fb_stats got a key error 2.1 url (%s)" % (url_string, ) |
|
| 422 |
- print "Get_fb_stats got a key error 3q (%s)" % (urllib.quote_plus(url_string)) |
|
| 423 |
- print "Get_fb_stats got a key error 4 (%s)" % (url % (urllib.quote_plus(url_string), encoded)) |
|
| 424 |
- print "Get_fb_stats got a key error 5 (%s) for url %s:" % (str(e), url % (urllib.quote_plus(url_string), encoded)) |
|
| 425 |
- return shares, comments, likes |
|
| 426 | 409 |
if len(data) > 20: |
| 427 | 410 |
d = json.loads(data)['engagement'] |
| 428 | 411 |
try: |
| ... | ... |
@@ -600,7 +583,7 @@ if __name__=='__main__': |
| 600 | 583 |
# If any work was done, then write files. |
| 601 | 584 |
# |
| 602 | 585 |
if any_entry_added: |
| 603 |
- weekend_stats, weekday_stats = analysis.Process_feed(items, rhs_metric, rhs_metric_times) |
|
| 586 |
+ weekend_stats, weekday_stats = analysis.process_feed(items, rhs_metric, rhs_metric_times) |
|
| 604 | 587 |
|
| 605 | 588 |
# We'll only look at the stats for the time 1:00 to 1:30 after posting. |
| 606 | 589 |
weekend_median, weekend_mean, weekend_sigma = weekend_stats[2] |
| 607 | 590 |