summaryrefslogtreecommitdiff
path: root/recolor_lib.py
blob: 3f292e066d3be6c7b9d1a994394657a9529750c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3

import re
from math import ceil
from random import randint
import asyncio
import aiohttp
import json


class accountError(Exception):
    pass

class user(object):
    @classmethod 
    async def init(cls, username, password):
        self = user()
        self.rs = aiohttp.ClientSession()
        self.username = username
        self.cooldown_time = 5
        async with self.rs.post('https://recolor.me/login?json', data = {
            'action':'login', 
            'account_name':username, 
            'account_password':password,
            'account_cookie':'1'}) as rp:

            print("Getting key for user {}...".format(self.username))
            json = await rp.json(content_type='text/html')
            if not json['account_id']:
                raise accountError("Failed to login user {}!".format(self.username))
            else:
                async with self.rs.get('https://recolor.me/') as homepage:
                    self.key = re.search("site.my_key = \'(.*)\';", await homepage.text()).groups()[0]
            await self.get_bits()

        return(self)

    async def get_bits(self):
        async with self.rs.get('https://recolor.me/account') as p:
            rp = await p.text() 
            self.total_bits = int(re.search("site.my_bits = (\d*);", rp).groups()[0])
            self.threashold = int(re.search("site.limit_bits = (\d*);", rp).groups()[0])
            self.daily_bits = int(re.search("site.daily_limit = (\d*);", rp).groups()[0])
            if self.daily_bits >= self.threashold:
                self.bitcapped = True 
            else:
                self.bitcapped = False

    
    async def beat_games(self):
        print("beating games for user {}".format(self.username))
        workers = []
        while not self.bitcapped:
            await self.get_bits()
            requests_succeeded = 0
            requests_needed = ceil((self.threashold - self.daily_bits) / 50) # 50 is how much we get per game
            while requests_needed > requests_succeeded:
                await asyncio.sleep(self.cooldown_time)
                async with self.rs.post('https://recolor.me/minigames', data = {
                    'action':'report',
                    'game':'invert',
                    'key':self.key
                    }) as w: 
                    if w.ok: 
                        requests_succeeded += 1
            await self.get_bits()
        print("bitcap acheived for {}!".format(self.username))

    async def complete_polls(self):
        print("User {} beating polls...".format(self.username))
        async with self.rs.get('https://recolor.me/polls') as p:
            polls = json.loads(re.search('rePoll\.polls = (\[.*\])\;', await p.text()).groups(1)[0])
            for poll in polls:
                await self.rs.post("https://recolor.me/?json", data = {
                    'page':'polls',
                    'action':'vote',
                    'key':self.key,
                    'poll':poll['repoll_id'],
                    'vote':randint(1,2)})
                await asyncio.sleep(self.cooldown_time)
            print("User {} done with polls!".format(self.username))

    async def maximize_money(self):
        await self.beat_games()
        await self.complete_polls()
    async def close(self):
        await self.rs.close()