Log in | Register
Forum > Site Discussion > Thread

Python script for sorting your most frequently favoured girls by how often you liked them

Jan 18, 2022 - edited Jan 19, 2022 - permalink

(quick and dirty coded) script that will count how often you favoured which girl on this imageboard, sort after number of images in your favorites and generate links to those sets of images.

#!/usr/bin/env python3

import requests
from lxml import html
from time import sleep

cookie = 0
username = "your own"
password = "your own"
glimit = 30


def login():
  csrftoken = requests.get('https://www.girlswithmuscle.com/login/').cookies["csrftoken"]

  r = requests.post('https://www.girlswithmuscle.com/login/', data={"csrfmiddlewaretoken": csrftoken, "username": username, "password": password}, headers={'referer': "https://www.girlswithmuscle.com/login/"}, cookies = {"csrftoken": csrftoken}, allow_redirects=False)
  return r.cookies["sessionid"];


s = login()

r = requests.get('https://www.girlswithmuscle.com/images/1/?favorited_by='+username+'&order=lastfavorited', cookies = {"sessionid": s})
tree = html.fromstring(r.content)
p = tree.xpath('//div[@class="paginator"]/text()')
p = p[2].replace('\n', "").split()
pages = p[3]
print(p[3] + "Pages")
persons_list = []

for page in range(1,int(pages)):
  sleep(1)
  print(page)
  r = requests.get('https://www.girlswithmuscle.com/images/'+str(page)+'/?favorited_by='+username+'&order=lastfavorited', cookies = {"sessionid": s})
  tree = html.fromstring(r.content)
  persons = tree.xpath('//div[@class="thumbnail-caption fitted-text"]/a/text()')
  for i in range(0,len(persons)):
    persons[i] = persons[i].lower()
    persons[i] = persons[i].replace("(r)", "")
    persons[i] = persons[i].replace("(c)", "")
    persons[i] = persons[i].replace("(l)", "")
    persons[i] = "".join(persons[i].rstrip().lstrip())

  for i in persons:
    #find in list of list
    found = False
    for j in persons_list:
      if(j[1]==i):
        j[0]=j[0]+1
        found = True
        break
    if not found:
      persons_list.append([1, i])

persons_list.sort(key = lambda e: e[0], reverse=False)

for person in persons_list:
  enc = person[1].replace(" ", "+")
  print('('+str(person[0])+') '+person[1] + '\n  https://www.girlswithmuscle.com/images/?name='+enc+'&favorited_by='+username)

output will be like

gwm_fav.py
.......
(10) juliana mota
  https://www.girlswithmuscle.com/images/?name=juliana+mota&favorited_by=coderlivffdot
(12) aline dessine
  https://www.girlswithmuscle.com/images/?name=aline+dessine&favorited_by=coderlivffdot
(22) carriejune anne bowlby
  https://www.girlswithmuscle.com/images/?name=carriejune+anne+bowlby&favorited_by=coderlivffdot

a lot more lines of course if you have lots of favourites.

Jan 18, 2022 - permalink

👍👍👍

Jan 18, 2022 - permalink

You need to change username and password variable accordingly for this to work. Also, you need requests and lxml which are both already included in some python distributions.

If you need assistance, feel free to ask.

Chainer
Jan 19, 2022 - permalink

Neat idea. One thing though: currently it doesn't rate-limit the requests it sends, which means that if you have a lot of pages of favorites, your IP might get blocked by the site as a result of using this script. It would be best to limit it so it sends no more than one request per second.

Jan 19, 2022 - permalink

Neat idea. One thing though: currently it doesn't rate-limit the requests it sends, which means that if you have a lot of pages of favorites, your IP might get blocked by the site as a result of using this script. It would be best to limit it so it sends no more than one request per second.

Good idea.

time.sleep(2)

The 2 is for 2 seconds or whatever you want to set it to.

Jan 19, 2022 - permalink

Neat idea. One thing though: currently it doesn't rate-limit the requests it sends, which means that if you have a lot of pages of favorites, your IP might get blocked by the site as a result of using this script. It would be best to limit it so it sends no more than one request per second.

edited script accordingly

« first < prev Page 1 of 1 next > last »