项目作者: erkghlerngm44

项目描述 :
/r/anime soulmate finder / affinity gatherer
高级语言: Python
项目地址: git://github.com/erkghlerngm44/r-anime-soulmate-finder.git
创建时间: 2017-03-18T13:44:49Z
项目社区:https://github.com/erkghlerngm44/r-anime-soulmate-finder

开源协议:MIT License

下载


r-anime-soulmate-finder

GitHub release
Github commits (since latest release)
PyUp
License

/r/anime soulmate finder / affinity gatherer.

Credit to TheEnigmaBlade for their
soulmate finder script,
which gave me a few ideas for parts of this script.

What do?

Processes comments from a chosen comment source, finds the
comment author’s MAL username (if they’ve specified it in their flair), retrieve
their list, calculate affinity and store the result. Dump results into a .csv
when done, or when you want to stop.

Setup

If the below sounds like jargon to you, or you’re too lazy to set this up,
read this.
It should set this all up for you.

  1. Download/fork/clone/whatever this repo.

  2. Create a Reddit client and put your
    client_id and client_secret under the reddit config in praw.ini.
    An example file can be found at praw.ini.example.

  3. Install dependencies (see “Dependencies” below).

  4. Run script (see “Usage” below).

Dependencies

  • MALAffinity
  • PRAW
  • Requests
  • UnicodeCSV

For the lazy:

  1. $ pip install -r requirements.txt

Usage

  1. $ python3 -m soulmate_finder --help
  2. usage: __main__.py [-h] (-c | -s SUBMISSION_ID | -f [LIMIT]) [-v | -q] [-b]
  3. [-z SIZE] [-t TIMEOUT]
  4. mal_username
  5. /r/anime soulmate finder
  6. positional arguments:
  7. mal_username
  8. optional arguments:
  9. -h, --help show this help message and exit
  10. comment sources:
  11. source of comments, which will be processed
  12. -c, --stream use the /r/anime comment stream as the comment source
  13. -s SUBMISSION_ID, --submission SUBMISSION_ID
  14. use the comments in a submission as the comment
  15. source. `SUBMISSION_ID` is the reddit submission id (6
  16. letter alphanumeric code between the '/comments/' and
  17. the thread title in the comments url, e.g.
  18. /r/anime/comments/{{CODE}}/free_talk_fridays...)
  19. -f [LIMIT], --ftf [LIMIT]
  20. use the comments in ftfs as the comment source.
  21. `LIMIT` specifies how many ftfs to use, working
  22. backwards from the current one (default: 1)
  23. logging/print options:
  24. controls the level of verbosity for this script
  25. -v, --verbose be more talkative (print more about what's going on)
  26. -q, --quiet quiet (silent) mode (only display errors)
  27. extra options:
  28. -b, --search-comment-body
  29. search the comment body for a mal url if a user
  30. doesn't have a flair
  31. -z SIZE, --buffer-size SIZE
  32. buffer size of file to write to, in bytes. dictates
  33. how many bytes to hold in buffer before writing to
  34. file (default: 512). assume the average row to be
  35. written is around 30-35 bytes
  36. -t TIMEOUT, --timeout TIMEOUT
  37. terminate the script after a specified amount of time
  38. (in seconds), if the comment source hasn't already
  39. been fully processed by then (default: never)

NOTE: The python3 part may be different for you, depending on your OS and/or Python install.
The variants (IIRC) are py, python, python3 and py -3. Try each, only specifying the argument
--version at the end, until your terminal tells you it’s using Python 3.x.x, then use that in place
of python3.

Importing the package

I don’t know why anyone would do this, but it is possible.

  1. import soulmate_finder as sf
  2. # Load up your scores into the `malaffinity.MALAffinity` class
  3. sf.pearson.init("MAL_USERNAME")
  4. # Choose comment source to process (pick one)
  5. comments = sf.sources.comment_stream()
  6. .submission("SUBMISSION_ID")
  7. .ftfs(limit=LIMIT)
  8. # Pass to the `main` function and hey presto
  9. sf.main(comments, ...)
  10. # A list of optional arguments can be found in the `main` function's docstring.

Comment Sources

Every comment from your chosen comment source gets processed, and for each comment, the
author’s “flair text” (which contains their MAL Profile/AnimeList URL) is extracted,
and affinity with that MAL user is calculated.

There are currently three comment sources that can be used:

A Thread/Submission

A SUBMISSION_ID is passed when specifying this option, and all comments in that
submission are processed.

Invocation:

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --submission SUBMISSION_ID

If you are running this on a “Find your MAL soulmate” thread (or something similar),
where, sometimes, users do not put the URL to their MAL profile in their flair, but
post it in their comment, you may want to run this with the --search-comment-body
(-b) argument, so the comment body is searched if there is no MAL URL in their flair.

This can be done as follows:

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --submission SUBMISSION_ID --search-comment-body

The Comment Stream

Comments get processed as they are posted onto the subreddit, in near-real-time.

Invocation:

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --stream

NOTE: As the stream never ends, you’ll have to Press CTRL+C when you want to stop processing
users, otherwise the script will keep going on forever.

If you are using this option, you’re probably not in a rush, and so might want to use the
--verbose (-v) argument, so you can see what the script is doing as it does it. This
isn’t enabled by default, as printing is time-taxing.

This can be done as follows:

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --stream --verbose

Past Free Talk Friday (FTF) Threads

Comments from past FTFs are processed.

Invocation:

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --ftf

The above will process comments from the most recent FTF. A LIMIT can be passed as well,
so you can specify how many FTFs you want to process (working backwards from the current one).

This can be done as follows (to use the 10 most recent FTFs):

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --ftf 10

If you are using this option, you may want to have the script process the comments as fast as
possible, so as to reduce the script runtime. You may want to consider using the --quiet
(-q) argument, so only errors get printed out, so no unnecessary time-taxing printing goes
on.

This can be done as follows:

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --ftf --quiet

Note that a LIMIT still can be passed after the --ftf if needed.

Also note that the “buffer size” can also be changed.

A small buffer size means the script writes to file more, which means if the script
abruptly closes, you won’t lose a lot of affinities, but it’ll make the script run a
lot slower. Conversely, a high buffer size means the script will write to file less,
which is helpful when you want to process a lot of users quickly, but you’ll lose a
lot of progress if the script closes abruptly.

The default is 512 bytes. Assume the average row that will get written per user is around 32 bytes.
With the default, progress will be saved to file every 16 rows or so (512 / 32 == 16).

This can be changed as follows:

  1. $ python3 -m soulmate_finder YOUR_MAL_USERNAME --ftf --buffer-size 2048 # ~ every 64 rows

FAQ

Q: I’m seeing references to affinity-gatherer in places here. What’s that?

I originally had the idea to name this soulmate-finder as it is right now,
but after running this script,
my kokoro broke
and I gave up on the idea.

I then got over it, accepted that I had shit taste and renamed everything to soulmate-finder.

Q: It’s broken!

I’m sorry, the code here is… shoddy… at best and I make it even worse every time I touch it. :(

Create an issue
or send me a message
and I’ll have a look.

Q: Your code/documentation/taste is shit!

[](#yuishrug)