Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # import pdb
- import re
- from time import gmtime, strftime, sleep
- def write_data(new_datapoint):
- output_path = '/media/USBHDD/PythonStudy/torrent_data_collection/data_one.csv'
- outfile = open(output_path, 'a')
- outfile.write(new_datapoint)
- outfile.close()
- forever = 0
- previous_data = "0"
- # for debugging: pdb.set_trace()
- while forever < 1:
- input_path = '/var/lib/transmission-daemon/info/stats.json'
- infile = open(input_path, "r")
- infile.seek(0)
- contents = infile.read()
- uploaded_bytes = re.search('"uploaded-bytes":\s(\d+)', contents)
- if uploaded_bytes:
- current_time = strftime("%Y-%m-%d %X", gmtime())
- current_data = uploaded_bytes.group(1)
- if current_data != previous_data:
- write_data(","+ current_time + "$" + uploaded_bytes.group(1))
- previous_data = uploaded_bytes.group(1)
- infile.close()
- sleep(5)
- else:
- print "couldn't write" + current_time
- infile.close
- sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement