Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Format of each line is:
- # date\ttime\tstore name\titem description\tcost\tmethod of payment
- #
- # We want elements 2 (store name) and 4 (cost)
- # We need to write them out to standard output, separated by a tab
- import sys
- import csv
- from datetime import datetime
- reader = csv.reader(sys.stdin, delimiter = "\t")
- writer = csv.writer(sys.stdout, delimiter = "\t", quotechar = '"', quoting = csv.QUOTE_ALL)
- reader.next()
- for line in reader:
- if len(line) == 19:
- author_id = line[3]
- hour = line[8].split("+") # "added-at" will be a list of 2 elements. We are interested to retrieve the first element
- post_hour = datetime.strptime(hour[0],'%Y-%m-%d %H:%M:%S.%f') # definition of post_hour as a datetime object
- post_hour = post_hour.hour
- print "{0}\t{1}".format(author_id, post_hour)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement