2016-12-31 17:56:37 +01:00
|
|
|
import sys, os, json, logging
|
|
|
|
|
from optparse import OptionParser
|
2016-09-09 15:15:10 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
reload(sys)
|
|
|
|
|
sys.setdefaultencoding('utf8')
|
2016-09-09 15:15:10 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
logging.info('1/4 setting up matplotlib')
|
|
|
|
|
# matplot view/windows
|
|
|
|
|
import matplotlib
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
matplotlib.interactive(True)
|
2016-09-09 15:15:10 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
logging.info('2/4 setting up pandas')
|
|
|
|
|
# pd display
|
|
|
|
|
import pandas as pd
|
|
|
|
|
pd.set_option('display.max_colwidth', 100)
|
2016-09-09 15:15:10 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
logging.info('3/4 loading nettime archive')
|
|
|
|
|
import nettime.archive
|
|
|
|
|
import nettime.query
|
|
|
|
|
import nettime.report
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
a = nettime.archive.Archive('nettime-l_2016-12-31.json.gz')
|
|
|
|
|
q = nettime.query.Query(a)
|
|
|
|
|
r = nettime.report.Report(q)
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
logging.info('4/4 reporting')
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
def text(command, params=None):
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
print command
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
func = {
|
|
|
|
|
"tab_msgs_threads_replies": r.tab_msgs_threads_replies,
|
|
|
|
|
"tab_avg_rep_msg_thrd": r.tab_avg_rep_msg_thrd,
|
|
|
|
|
"tab_activity_from_ranking": r.tab_activity_from_ranking,
|
|
|
|
|
"tab_content_length_from_ranking": r.tab_content_length_from_ranking,
|
|
|
|
|
"tab_threads_ranking": r.tab_threads_ranking,
|
|
|
|
|
"tab_threads_ranking_year": r.tab_threads_ranking_year
|
|
|
|
|
}
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
print func[command]
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
return func[command]()
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
def html(command, params=None):
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
func = {
|
|
|
|
|
"html_msgs_threads_replies": r.html_msgs_threads_replies,
|
|
|
|
|
"html_avg_rep_msg_thrd": r.html_avg_rep_msg_thrd,
|
|
|
|
|
"html_activity_from_ranking": r.html_activity_from_ranking,
|
|
|
|
|
"html_content_length_from_ranking": r.html_content_length_from_ranking,
|
|
|
|
|
"html_threads_ranking": r.html_threads_ranking,
|
|
|
|
|
"html_threads_ranking_year": r.html_threads_ranking_year
|
|
|
|
|
}
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
return func[command]()
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
def run(options):
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
if options.output_file and os.path.isfile(options.output_file):
|
|
|
|
|
with open(options.output_file, 'r') as fp:
|
|
|
|
|
out = fp.read() # not optimal but will do
|
|
|
|
|
else:
|
|
|
|
|
print 'No output-file. Nothing to do.'
|
|
|
|
|
return
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
if options.input_script and os.path.isfile(options.input_script):
|
|
|
|
|
with open(options.input_script, 'r') as fp:
|
|
|
|
|
input_script = json.load(fp)
|
|
|
|
|
else:
|
|
|
|
|
print 'No input-script. Nothing to do.'
|
|
|
|
|
return
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
for cmd in input_script:
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
if cmd['format'] == 'html':
|
|
|
|
|
func = html
|
|
|
|
|
elif cmd['format'] == 'text':
|
|
|
|
|
func = text
|
|
|
|
|
else:
|
|
|
|
|
continue
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
res = func(cmd['command'])
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
if res is not None:
|
|
|
|
|
out = out.replace(cmd['replace'], res)
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
with open(options.output_file, 'w') as fp:
|
|
|
|
|
fp.write(out) # not optimal but will do
|
2016-09-11 14:24:59 +02:00
|
|
|
|
|
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
if __name__ == "__main__":
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
p = OptionParser();
|
|
|
|
|
p.add_option('-i', '--input-script', action="store", help="..")
|
|
|
|
|
p.add_option('-o', '--output-file', action="store", help="..")
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
options, args = p.parse_args()
|
2016-09-11 14:24:59 +02:00
|
|
|
|
2016-12-31 17:56:37 +01:00
|
|
|
run(options)
|
2016-09-09 15:15:10 +02:00
|
|
|
|
|
|
|
|
|