#!/bin/bash

APIKEY="bbd51c6a02be64c3065dbadc88a1d372_428309"

LoadHotOrNot () {
  #echo "Parameter #1 is $1"
  echo "Durchgang $2"

  for NAME in $1
  do
    echo "Parameter #1 is ${NAME}"
    DATA_LOAD=$( curl --silent 'https://www.yoomee.love/api/v2/hot_or_not' -H 'Pragma: no-cache' -H 'Origin: https://www.yoomee.love' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Client: Web/Commit: 90c2071ad883f5435ccc5eed18825f18ec606341' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://www.yoomee.love/matchgame' -H 'Cookie: device_view=full; _ga=GA1.2.1970750271.1530997424; _gid=GA1.2.676055672.1531220771; lovidoo_session=hv6f9sd7v36fg9vek5rvtha1l5; _gat_gtag_UA_15495641_17=1' -H 'Connection: keep-alive' -H "x-api-key: ${APIKEY}" --data-binary "{\"slug\":\"${NAME}\",\"hot\":true}" --compressed )
    PROFILE_ID=$(echo "${DATA_LOAD}" | jq --raw-output '.bookmarks[0].bookmarked_profile.profile_id')
    PROFILE_SLUG=$(echo "${DATA_LOAD}" | jq --raw-output '.bookmarks[0].bookmarked_profile.slug')
    if [ -e "./yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_from_match_game.json" ]; then
      continue
    fi 
    echo "${DATA_LOAD}" | jq --raw-output '.bookmarks[0].bookmarked_profile' - | cat > yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_from_match_game.json
    jq --raw-output ".profiles[] | select(.profile_id | . and contains(${PROFILE_ID}))" yoomee/hotornot.$2.json | cat > yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_from_match_game_list.json
    curl --silent "https://www.yoomee.love/api/v1/profile/jomaar/bookmarks/${PROFILE_SLUG}" -X DELETE -H 'Pragma: no-cache' -H 'Origin: https://www.yoomee.love' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Client: Web/Commit: 90c2071ad883f5435ccc5eed18825f18ec606341' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://www.yoomee.love/profile/liebezenzi' -H 'Cookie: device_view=full; _ga=GA1.2.1970750271.1530997424; _gid=GA1.2.676055672.1531220771; lovidoo_session=hv6f9sd7v36fg9vek5rvtha1l5; _gat_gtag_UA_15495641_17=1' -H 'Connection: keep-alive' -H "x-api-key: ${APIKEY}" --compressed > /dev/null
    curl --silent "https://www.yoomee.love/api/v1/profile/jomaar/bookmarks/${PROFILE_SLUG}" -H 'Pragma: no-cache' -H 'Origin: https://www.yoomee.love' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Client: Web/Commit: 90c2071ad883f5435ccc5eed18825f18ec606341' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://www.yoomee.love/profile/liebezenzi' -H 'Cookie: device_view=full; _ga=GA1.2.1970750271.1530997424; _gid=GA1.2.676055672.1531220771; lovidoo_session=hv6f9sd7v36fg9vek5rvtha1l5; _gat_gtag_UA_15495641_17=1' -H 'Connection: keep-alive' -H "x-api-key: ${APIKEY}" --data-binary '{}' --compressed | jq --raw-output '.payload.bookmark.bookmarked_profile' - | cat > yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_from_inprofile_like.json
    jq -s '.[0] as $o1 | .[1] as $o2 | .[2] as $o3 | ($o1 + $o2 + $o3) | .settings = ($o1.settings + $o2.settings + $o3.settings) | .images = ($o1.images + $o2.images + $o3.images)' yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_from_match_game.json yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_from_inprofile_like.json  yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_from_match_game_list.json | cat > yoomee/${PROFILE_ID}.${PROFILE_SLUG}.profiledata_merged.json
  done
}

#for NUMBER in 1
for NUMBER in {400..250000}
do
  curl -i "https://www.yoomee.love/api/v2/hot_or_not?limit=12&offset=0" -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Client: Web/Commit: 90c2071ad883f5435ccc5eed18825f18ec606341' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://www.yoomee.love/matchgame' -H 'Cookie: device_view=full; _ga=GA1.2.1970750271.1530997424; _gid=GA1.2.676055672.1531220771; lovidoo_session=39eb32vrn7s6kh17uar83pgj67; _gat_gtag_UA_15495641_17=1' -H 'Connection: keep-alive' -H "x-api-key: ${APIKEY}" --compressed > yoomee/hotornot.${NUMBER}.json
  LoadHotOrNot "$( jq --raw-output '.profiles[].slug' yoomee/hotornot.${NUMBER}.json )" "${NUMBER}"
  if [ -e "./yoomee/stop.yoomee" ]; then
    break
  fi 
done


# curl 'https://www.yoomee.love/api/v3/likes?limit=60&offset=0' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Client: Web/Commit: 90c2071ad883f5435ccc5eed18825f18ec606341' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://www.yoomee.love/bookmarks' -H 'Cookie: device_view=full; _ga=GA1.2.1970750271.1530997424; _gid=GA1.2.676055672.1531220771; lovidoo_session=39eb32vrn7s6kh17uar83pgj67' -H 'Connection: keep-alive' -H 'x-api-key: bbd51c6a02be64c3065dbadc88a1d372_428309' --compressed > mydelete_list.json
# jq --raw-output '.list[].slug' mydelete_list.json | while read LINE; do curl "https://www.yoomee.love/api/v1/profile/jomaar/bookmarks/$LINE" -X DELETE -H 'Pragma: no-cache' -H 'Origin: https://www.yoomee.love' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Client: Web/Commit: 90c2071ad883f5435ccc5eed18825f18ec606341' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://www.yoomee.love/profile/loveangel26' -H 'Cookie: device_view=full; _ga=GA1.2.1970750271.1530997424; _gid=GA1.2.676055672.1531220771; lovidoo_session=39eb32vrn7s6kh17uar83pgj67; _gat_gtag_UA_15495641_17=1' -H 'Connection: keep-alive' -H 'x-api-key: bbd51c6a02be64c3065dbadc88a1d372_428309' --compressed; done

# Markes as fakes
# grep -o '"fake": true' *_merged.json | wc -l
# 471

# known fakes by mail address
# grep -o -E '(flirtwiese.fake|anonymous.love|rajahaski.ru|mobiletrend.de)' *_merged.json | wc -l
# 610

# known fakes by mail address and fake tag
# grep -o -m1 -E '("fake": true|flirtwiese.fake|anonymous.love|rajahaski.ru|mobiletrend.de)' *_merged.json | wc -l
# 610

# Accounts without known fake accounts
# grep -o -L -E '(flirtwiese.fake|anonymous.love|rajahaski.ru|mobiletrend.de)' *_merged.json | wc -l
# 618
