Advertisement
Guest User

Untitled

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