<commit_before>#!/usr/bin/python
from datetime import datetime
import getpass
# The md5 module is deprecated since Python 2.5
try:
    import hashlib
    md5hash = hashlib.md5
except ImportError:
    import md5
    md5hash = md5.new
from optparse import OptionParser
import time
from urllib import urlencode
from urllib2 import urlopen


usage = "%prog <USERNAME> <SERVER> <SCROBBLE DUMP>"
parser = OptionParser(usage=usage)
opts,args = parser.parse_args()
if len(args) != 3:
    parser.error("All arguments are required.")

username,server,data = args
if server[:7] != "http://":
    server = "http://%s" % (server,)
password = <PASSWORD>()

timestamp = int(time.time())
token = md5hash(md5hash(password).hexdigest() + str(timestamp)).hexdigest()
auth_url = "%s/?hs=true&p=1.2&u=%s&t=%d&a=%s&c=imp" % (server, username,
                                                       timestamp, token)
response = urlopen(auth_url).read()
lines = response.split("\n")
if lines[0] != "OK":
    parser.error("Server returned: %s" % (response,))
session_id = lines[1]
submit_url = lines[3]

def post(post_data):
    post_data.append(('s', session_id))
    response = urlopen(submit_url, urlencode(post_data)).read()
    if response != "OK\n":
        parser.error("Server returned: %s" % (response,))

i = 0
post_data = []
for line in file(data):
    artist,track,timestamp = line.strip().split("\t")
    dt = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ")
    timestamp = str(int(time.mktime(dt.timetuple())))
    post_data += [('a[%d]' % i, artist), ('t[%d]' % i, track),
                  ('i[%d]' % i, timestamp)]<commit_msg>import.py shouldn't convert to the wrong timezone<commit_after>#!/usr/bin/python
from datetime import datetime
import getpass
# The md5 module is deprecated since Python 2.5
try:
    import hashlib
    md5hash = hashlib.md5
except ImportError:
    import md5
    md5hash = md5.new
from optparse import OptionParser
import time
from urllib import urlencode
from urllib2 import urlopen


usage = "%prog <USERNAME> <SERVER> <SCROBBLE DUMP>"
parser = OptionParser(usage=usage)
opts,args = parser.parse_args()
if len(args) != 3:
    parser.error("All arguments are required.")

username,server,data = args
if server[:7] != "http://":
    server = "http://%s" % (server,)
password = <PASSWORD>()

timestamp = int(time.time())
token = md5hash(md5hash(password).hexdigest() + str(timestamp)).hexdigest()
auth_url = "%s/?hs=true&p=1.2&u=%s&t=%d&a=%s&c=imp" % (server, username,
                                                       timestamp, token)
response = urlopen(auth_url).read()
lines = response.split("\n")
if lines[0] != "OK":
    parser.error("Server returned: %s" % (response,))
session_id = lines[1]
submit_url = lines[3]

def post(post_data):
    post_data.append(('s', session_id))
    response = urlopen(submit_url, urlencode(post_data)).read()
    if response != "OK\n":
        parser.error("Server returned: %s" % (response,))

i = 0
post_data = []
for line in file(data):
    artist,track,timestamp = line.strip().split("\t")
    dt = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ")
    timestamp = str(int(time.mktime(dt.utctimetuple())))
    post_data += [('a[%d]' % i, artist), ('t[%d]' % i, track),
                  ('i[%d]' % i, timestamp)]
{'fraction_non_alphanumeric': 0.16946053032612007, 'fraction_numerical': 0.011581834806461445, 'mean_word_length': 3.729106628242075, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6303115', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1103, 'n_words': 267}