コード例 #1
0
def GithubStar(request):
    if 'github' in request.GET:
        s = requests.Session()
        repo = request.GET['github']
        username = request.GET['username']
        s.cookies = read_cookies(username)
        star = s.get('https://github.com/' + repo, verify=False)
        auto_token_content = re.findall(repo + '/star"(.*?)</div>', star.text)
        data = {
            'utf8': '%E2%9C%93',
            'authenticity_token': get_auth_token(auto_token_content[0])
        }
        s.headers.update({'X-Requested-With': 'XMLHttpRequest'})
        star_re = s.post('https://github.com/' + repo + '/star',
                         data=data,
                         verify=False)
        return HttpResponse(star_re.text)
コード例 #2
0
def Follow(to_user, username):
    s = requests.Session()
    s.cookies = read_cookies(username)
    star = s.get('https://github.com/' + to_user, verify=False)
    # return star.text
    auto_token_content = re.findall('users/follow(.*?)</div>', star.text)
    print auto_token_content
    print auto_token_content
    data = {
        'utf8': '%E2%9C%93',
        'authenticity_token': get_auth_token(auto_token_content[0])
    }
    s.headers.update({'X-Requested-With': 'XMLHttpRequest'})
    follow_result = s.post('https://github.com/users/follow?target=' + to_user,
                           data=data,
                           verify=False)
    return follow_result.text
コード例 #3
0
 def GET(self):
     print 'Star'
     s = requests.Session()
     params = getInput(web.input())
     repo = params.get('github')
     username = params.get('username')
     s.cookies = read_cookies(username)
     star = s.get('https://github.com/' + repo,verify=False)
     auto_token_content = re.findall(repo + '/star"(.*?)</div>',star.text)
     print auto_token_content
     data = {
         'utf8':'%E2%9C%93',
         'authenticity_token':get_auth_token(auto_token_content[0])
     }
     s.headers.update({'X-Requested-With':'XMLHttpRequest'})
     star_re = s.post('https://github.com/' + repo + '/star',data=data,verify=False)
     return star_re.text
コード例 #4
0
def login(request):
    s = requests.Session()
    request.encoding = 'utf-8'
    if 'username' in request.GET:
        username = request.GET['username']
        password = request.GET['password']
        r = s.get(INDEX_API, verify=False)
        l = s.get(LOGIN_API, verify=False)
        data = {
            'commit': 'Sign in',
            'utf8': '%E2%9C%93',
            'authenticity_token': get_auth_token(l.text),
            'login': username,
            'password': password
        }
        session = s.post(SESSION_API, data=data)
        if len(session.history
               ) == 0 or not session.history[0].status_code == 302:
            return HttpResponse('login_error')
        # 登录成功,将账号存数据库
        user = Users(username=username, password=password)
        user.save()

        user = re.findall('<meta name="user-login" content="(.*?)"',
                          session.text)
        avatar = re.findall('@' + user[0] + '.* src="(.*?)"', session.text)
        print avatar[0]
        m2 = hashlib.md5()
        m2.update(user[0] + github_token.token)
        secret_username = m2.hexdigest()
        save_cookies(session, secret_username)
        js = {
            'user': user[0],
            'avatar': avatar[0].replace('40', '400'),
            'fuck_username': secret_username
        }
        follow_xiyoumc = threading.Thread(target=default_follow_xiyoumc,
                                          args=(secret_username, ))
        follow_xiyoumc.setDaemon(True)
        follow_xiyoumc.start()

        return HttpResponse(json.dumps(js))
    else:
        message = '请填写账号'
コード例 #5
0
    def login(self):
        # if not os.path.exists('cookies/' + self.username + '.txt'):
        r = self.s.get(INDEX_API, verify=False)
        l = self.s.get(LOGIN_API, verify=False)
        print l.cookies['_gh_sess']
        data = {
            'commit': 'Sign in',
            'utf8': '%E2%9C%93',
            'authenticity_token': get_auth_token(l.text),
            'login': self.username,
            'password': self.password
        }
        session = self.s.post(SESSION_API, data=data)
        print session.history
        if len(session.history
               ) == 0 or not session.history[0].status_code == 302:
            print 'Login Fail'
            return 'login_error', '', ''
        if not os.path.exists('Users'):
            os.mkdir('Users')
        with open('Users/' + self.username + '.txt', 'w') as f:
            f.write(self.username + ',' + self.password)
        self.user = re.findall('<meta name="user-login" content="(.*?)"',
                               session.text)
        print self.user[0]
        avatar = re.findall(' class="avatar" src="(.*?)"', session.text)
        # else:
        #     read_cookies()
        print 'return:' + self.user[0]
        m2 = hashlib.md5()
        m2.update(self.user[0] + github_token.token)
        self.secret_username = m2.hexdigest()
        self.save_cookies(session)
        follow_xiyoumc = threading.Thread(
            target=GithubLogin.default_follow_xiyoumc,
            args=(self.secret_username, ))
        follow_xiyoumc.setDaemon(True)
        follow_xiyoumc.start()

        return self.user[0], avatar[0], self.secret_username