forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_by_code.py
More file actions
76 lines (60 loc) · 1.95 KB
/
Copy pathsearch_by_code.py
File metadata and controls
76 lines (60 loc) · 1.95 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
LOGIN = None
PASSWORD = None
# http://user:password@proxy_host:proxy_port
PROXY = None
if PROXY:
import os
os.environ['http_proxy'] = PROXY
from github import Github
gh = Github(LOGIN, PASSWORD)
# print(list(gh.search_code('requests auth github filename:.py language:python')[:5]))
search_query = 'requests auth github filename:.py language:python'
# print(gh.search_code(search_query).totalCount)
# The Search API has a custom rate limit. For requests using Basic Authentication, OAuth, or client ID and
# secret, you can make up to 30 requests per minute. For unauthenticated requests, the rate limit allows
# you to make up to 10 requests per minute.
#
# Если авторизован, то каждые 2 секунды можно слать запрос, иначе каждые 6
timeout = 2 if LOGIN and PASSWORD else 6
# Немного добавить на всякий
timeout += 0.5
import time
search_result = gh.search_code(search_query)
total_count = search_result.totalCount
page = 0
data = search_result.get_page(page)
print(data[0])
print(dir(data[0]))
print(data[0].url)
print(data[0].content)
from base64 import b64decode as base64_to_text
print(base64_to_text(data[0].content.encode()).decode())
print(data[0].html_url)
# get user from repo url
user = data[0].html_url.split('/')[3]
print(user)
# i = 1
# while total_count > 0:
# data = search_result.get_page(page)
# for result in data:
# print(i, result)
# i += 1
#
# print('page: {}, total: {}, results: {}'.format(page, total_count, len(data)))
# page += 1
# total_count -= len(data)
#
# # Задержка запросов, чтобы гитхаб не блокировал временно доступ
# time.sleep(timeout)
# i = 1
# for match in gh.search_code(search_query):
# print(i, match)
# i += 1
#
# time.sleep(timeout)
#
# # print(dir(match))
# # break