Skip to content

Commit

Permalink
Merge pull request #104 from soxoj/speed-up
Browse files Browse the repository at this point in the history
Accelerated module import time
  • Loading branch information
soxoj authored Nov 15, 2021
2 parents d97fa61 + 386a64d commit b80782e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions socid_extractor/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import logging
from http.cookies import SimpleCookie
from bs4 import BeautifulSoup as bs

import requests

from .schemes import *
from .postprocessor import POSTPROCESSORS
Expand All @@ -21,6 +18,8 @@ def parse(url, cookies_str='', timeout=3, headers={}):
req_headers = dict(HEADERS)
req_headers.update(headers)
logging.debug(req_headers)

import requests
page = requests.get(url, headers=req_headers, cookies=cookies, allow_redirects=True, timeout=(timeout, timeout))
logging.debug('Server response: \'%s\'', page.text)
logging.debug('Status code: %d', page.status_code)
Expand Down Expand Up @@ -129,6 +128,7 @@ def extract(page):
values = map_fields(scheme_data, transformed_data)

if use_html_parser:
from bs4 import BeautifulSoup as bs
soup = bs(page, 'html.parser')
for name, get_field in scheme_data['fields'].items():
try:
Expand Down
2 changes: 1 addition & 1 deletion socid_extractor/postprocessor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import requests


class Gravatar:
Expand Down Expand Up @@ -28,6 +27,7 @@ def make_en_url(self):
return f'https://en.gravatar.com/{self.email_hash}'

def get_username(self):
import requests
gravatar_account_location = requests.head(self.make_en_url())
username = gravatar_account_location.headers.get('location', '').strip('/')
if username == 'profiles/no-such-user':
Expand Down
7 changes: 3 additions & 4 deletions socid_extractor/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from http.cookiejar import MozillaCookieJar
from http.cookies import Morsel

import logging
import math
import re
import requests
from datetime import datetime
from http.cookies import SimpleCookie


def import_cookiejar(filename):
from http.cookiejar import MozillaCookieJar
cookies_obj = MozillaCookieJar(filename)
cookies_obj.load(ignore_discard=True, ignore_expires=True)
cookies = {}
Expand Down Expand Up @@ -111,5 +108,7 @@ def extract_periscope_uid(text):
return userId.group(1)

def get_mymail_uid(username):
# TODO: move to external function
import requests
req = requests.get('http://appsmail.ru/platform/mail/' + username)
return req.json()['uid']

0 comments on commit b80782e

Please sign in to comment.