Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions tasks/get_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
)
def prepare():
r = redis.from_url(os.environ.get("REDIS_URL"))
next_repo = r.spop("github_repos")
while next_repo:
while next_repo := r.spop("github_repos"):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function prepare refactored with the following changes:

next_repo = next_repo.decode()
users = []
_get_star_gazers(
Expand All @@ -24,11 +23,10 @@ def prepare():
os.environ.get("GITHUB_CLIENT_SECRET"),
user_profiles=users,
)
f = "ghost_list/1_{}_.json".format(next_repo.replace("/", "_"))
f = f'ghost_list/1_{next_repo.replace("/", "_")}_.json'
for user in users:
user_info = {"github_info": user, "file": f}
r.sadd("github_list", json.dumps(user_info))
next_repo = r.spop("github_repos")


@task(
Expand Down Expand Up @@ -63,9 +61,7 @@ def get_email():
if response["email"] is not None:
email_count += 1
time.sleep(0.3)
elif resp.status_code == 404:
pass
else:
elif resp.status_code != 404:
Comment on lines -66 to +64
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_email refactored with the following changes:

r.sadd("github_list", json.dumps(profile))
print("failed --- i ", i, email_count)
print(resp.status_code)
Expand All @@ -82,8 +78,7 @@ def clean_redis_set():
engine = create_engine(os.environ.get("DB_CONNECTION_STRING"))
connection = engine.connect()
r = redis.from_url(os.environ.get("REDIS_URL"))
profile = r.spop("finished_profiles")
while profile:
while profile := r.spop("finished_profiles"):
Comment on lines -85 to +81
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function clean_redis_set refactored with the following changes:

profile = json.loads(profile.decode())
# move this into the SQL DB
try:
Expand All @@ -105,7 +100,6 @@ def clean_redis_set():
except:
print("failed on ", profile)
r.sadd("finished_profiles_error", json.dumps(profile))
profile = r.spop("finished_profiles")
connection.close()


Expand All @@ -125,27 +119,13 @@ def _create_new_lead(
raw=None,
):
connection.execute(
"insert into github_leads (source_file, source_repo, gh_login, gh_id, gh_name, gh_email, gh_twitter, gh_public_repos, gh_followers, gh_created_at, gh_updated_at, raw) values ('{}', '{}', '{}', '{}', '{}', '{}', '{}', {}, {}, '{}', '{}', '{}')".format(
source_file,
source_repo,
gh_login,
gh_id,
gh_name,
gh_email,
gh_twitter,
gh_public_repos,
gh_followers,
gh_created_at,
gh_updated_at,
raw,
)
f"insert into github_leads (source_file, source_repo, gh_login, gh_id, gh_name, gh_email, gh_twitter, gh_public_repos, gh_followers, gh_created_at, gh_updated_at, raw) values ('{source_file}', '{source_repo}', '{gh_login}', '{gh_id}', '{gh_name}', '{gh_email}', '{gh_twitter}', {gh_public_repos}, {gh_followers}, '{gh_created_at}', '{gh_updated_at}', '{raw}')"
Comment on lines -128 to +122
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _create_new_lead refactored with the following changes:

)


def _get_star_gazers(repo, client_id, client_secret, page=1, user_profiles=[]):
url = "https://api.github.com/repos/{}/stargazers?per_page=100&page={}".format(
repo, page
)
url = f"https://api.github.com/repos/{repo}/stargazers?per_page=100&page={page}"

Comment on lines -146 to +128
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_star_gazers refactored with the following changes:

resp = requests.get(url, auth=(client_id, client_secret))
if resp.status_code == 200:
response = resp.json()
Expand Down Expand Up @@ -173,10 +153,8 @@ def _get_star_gazers(repo, client_id, client_secret, page=1, user_profiles=[]):

def _get_repo(file_name):
main_name = "_".join(file_name.split("/")[1].split("_")[1:])
github_repo_name = "{}/{}".format(main_name.split("_")[0], main_name.split("_")[1])
return github_repo_name
return f'{main_name.split("_")[0]}/{main_name.split("_")[1]}'
Comment on lines -176 to +156
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_repo refactored with the following changes:



if __name__ == "__main__":
pass
pass
Comment on lines -180 to +159
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 180-181 refactored with the following changes: