From e96991ecb4829efc1efa2e1c84d81b6d0fce5a92 Mon Sep 17 00:00:00 2001 From: songbird175 Date: Mon, 21 Mar 2016 21:50:24 -0400 Subject: [PATCH 1/2] Counter code --- counter.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/counter.py b/counter.py index 1e2fb56..f60d497 100644 --- a/counter.py +++ b/counter.py @@ -29,7 +29,22 @@ def update_counter(file_name, reset=False): >>> update_counter('blah2.txt') 2 """ - pass + if exists(file_name) == False or reset == True: + counter_file = open(file_name, 'w') + counter = 1 + dump(counter, counter_file) + counter_file.close() + return counter + else: + counter_file = open(file_name, 'r+') + counter = load(counter_file) + counter += 1 + counter_file.seek(0,0) #without this, the updated counter value gets added to the end of the document. Only the first line of the doc is loaded by load() + dump(counter, counter_file) + counter_file.close() + return counter + + if __name__ == '__main__': if len(sys.argv) < 2: From 35508eb78b595cf150cb40f9fe7e1a2fa485db9c Mon Sep 17 00:00:00 2001 From: songbird175 Date: Mon, 21 Mar 2016 21:50:45 -0400 Subject: [PATCH 2/2] Text files --- blah.txt | 2 ++ blah2.txt | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 blah.txt create mode 100644 blah2.txt diff --git a/blah.txt b/blah.txt new file mode 100644 index 0000000..ba8c4c4 --- /dev/null +++ b/blah.txt @@ -0,0 +1,2 @@ +I3 +. \ No newline at end of file diff --git a/blah2.txt b/blah2.txt new file mode 100644 index 0000000..1cc9408 --- /dev/null +++ b/blah2.txt @@ -0,0 +1,2 @@ +I2 +. \ No newline at end of file