Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import argparse
  2. import csv
  3. import urlparse
  4.  
  5. from Common.Api import member_ids
  6.  
  7. def main(file_name):
  8. with open(file_name, 'rU') as infile:
  9. reader = csv.DictReader(infile)
  10. with open('result.csv', 'w') as outfile:
  11. writer = csv.writer(outfile)
  12. for row in reader:
  13. click_id = urlparse.parse_qs(
  14. urlparse.urlparse(row['Original URL']).query)['clickid'][0]
  15. split_decoded_id = member_ids._decode(click_id).split('~')
  16. row['mid'] = split_decoded_id[0]
  17. row['campaign_id'] = split_decoded_id[1]
  18. del row['Original URL']
  19. writer.writerow(row.values())
  20.  
  21. if __name__ == '__main__':
  22. parser = argparse.ArgumentParser()
  23. parser.add_argument(
  24. "file_name",
  25. help="path to CSV file")
  26.  
  27. args = parser.parse_args()
  28. main(args.file_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement