summaryrefslogtreecommitdiff
path: root/cupinder.py
blob: 7835ea14f3c4dca3bf1d99bf48cd3fdc61e865fc (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

import argparse
from time import sleep

import config
from db import HumanKind
from facebook import FacebookAPI
from nl import LanguageIdentifier
from tinder import TinderAPI


def connect():
    """Establish a connection to Facebook/Tinder."""

    fb = FacebookAPI(config.facebook_email, config.facebook_password)

    fb_id = fb.get_user_id()

    print('[i] Facebook ID: ' + fb_id)

    fb_token = fb.get_tinder_token()

    print('[i] Tinder token: ' + fb_token)

    tinder = TinderAPI(fb_id, fb_token)

    print('[i] Tinder auth token: ' + tinder.get_auth_token())

    print('[i] Remaining likes: %d' % tinder.get_remaining_likes())

    wait = tinder.can_like_in()

    if wait == 0:
        print('[i] Time to like!')
    else:
        print('[i] We have to wait %d minute%s before liking...' % (wait, 's' if wait > 1 else ''))

    return tinder


if __name__=='__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument('-g', '--grab', help='Grab profiles from Tinder', action='store_true')
    parser.add_argument('-p', '--process', help='Process stored Tinder profiles', action='store_true')
    parser.add_argument('--dump-new', help='Extract newly stored Tinder profiles', action='store_true')
    parser.add_argument('--dump-all', help='Extract all stored Tinder profiles', action='store_true')
    parser.add_argument('-s', '--superlike', help='Superlike a given Tinder profile using its ID', type=str)

    args = parser.parse_args()


    db = HumanKind()


    if args.grab:

        tinder = connect()

        extra = 0

        while True:

            profiles = tinder.get_recommendations(1)

            for p in profiles:

                if not(db.has_profile_id(p)):

                    extra += 1

                    print(p)
                    db.store_profile(p)

            if extra == 0:
                print('[!] No new profiles to grab! Exiting...')
                break

            print('[i] Loaded ' + config.COLOR_LIKE + '%d' % extra + config.COLOR_RESET \
                  + ' new profile%s... Taking some rest now!' % ('s' if extra > 2 else ''))

            sleep(5 * 60)


    elif args.process:

        tinder = connect()

        lid = LanguageIdentifier()

        profiles = db.load_new_profiles()

        remaining = tinder.get_remaining_likes()

        for p in profiles:

            like = True

            age = p.compute_age()

            if not(age is None):
                if age < config.MIN_AGE or age > config.MAX_AGE:
                    like = False

            if p._distance_mi > config.MAX_DISTANCE_IN_MI:
                like = False

            if like and not(p._bio is None):

                language = lid.detect_language(p._bio)

                like = (language == config.TARGET_LANGUAGE)

            if like and not(p._bio is None):

                text = p._bio.lower()

                for kwd in config.BLACK_LIST_KEYWORDS:
                    if kwd in text:
                        like = False
                        break

            if like:

                if remaining == 0:
                    print('[!] No more likes available. Exiting...')
                    break

                remaining -= 1

                print('[*] %s: ' % p._name + config.COLOR_LIKE + 'like!' + config.COLOR_RESET)

                tinder.like(p._id)
                db.mark_profile_as_liked(p)

            else:

                print('[*] %s: ' % p._name + config.COLOR_PASS + 'pass' + config.COLOR_RESET)

                tinder.dislike(p._id)
                db.mark_profile_as_passed(p)

            sleep(5)


    elif args.dump_new:

        profiles = db.load_new_profiles()

        for p in profiles:

            print('[i] Extracting information about %s (id=%s)...' % (p._name, p._id))

            p.output()
            db.mark_profile_as_extracted(p)


    elif args.dump_all:

        profiles = db.load_all_profiles()

        for p in profiles:

            print('[i] Extracting information about %s (id=%s)...' % (p._name, p._id))

            p.output()
            db.mark_profile_as_extracted(p)


    elif args.superlike:

        tinder = connect()

        uid = args.superlike

        profile = db.load_profile(uid)

        tinder.superlike(uid)

        if profile:

            db.mark_profile_as_superliked(profile)

            print('[*] %s: ' % profile._name + config.COLOR_LIKE + 'superlike!' + config.COLOR_RESET)

        else:

            print('[*] ' + config.COLOR_LIKE + 'Superliked' + config.COLOR_RESET + ' ' + uid)