diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2013-09-29 05:12:56 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2013-09-29 05:12:56 -0400 |
| commit | 19346fa9068878af516cdb670bea4f791337507b (patch) | |
| tree | 54d4fa5a82b2e0305f3b050dc1ebb53ec9d82a5d /process.py | |
| download | lastfm-19346fa9068878af516cdb670bea4f791337507b.tar.gz | |
Initial commit
Diffstat (limited to 'process.py')
| -rw-r--r-- | process.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/process.py b/process.py new file mode 100644 index 0000000..a0ce5e5 --- /dev/null +++ b/process.py @@ -0,0 +1,29 @@ +from __future__ import with_statement +from lastfm import get_friends, init +import sys +import time + + +def process(filename): + i = 0 + with open(filename) as ih: + to_do = set(line.strip() for line in ih) + done = set([]) + try: + with open(filename + ".out") as ih: + done = set(line.strip().split("\t")[0] for line in ih) + except IOError: + pass + with open(filename + ".out", "a") as oh: + for user in to_do - done: + i += 1 + friends = get_friends(user) + friends = [friend["name"] for friend in friends] + if friends: + oh.write(user.decode("utf8").encode("utf8") + "\t" + + u"\t".join(friends).encode("utf8") + "\n") + time.sleep(0.1) + +if __name__ == "__main__": + init(sys.argv[1]) + process(sys.argv[2]) |
