Skip to content

Commit

Permalink
v2.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwickerhf committed Dec 5, 2020
1 parent 9a6f5e8 commit dc92bf4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
36 changes: 24 additions & 12 deletions instaclient/classes/baseprofile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import requests
import requests, logging
from instaclient.errors.common import InvalidInstaRequestError, InvalidInstaSchemaError
from instaclient.client.urls import GraphUrls
from instaclient.classes.instaobject import InstaBaseObject

logger = logging.getLogger(__name__)

class BaseProfile(InstaBaseObject):
def __init__(self, id:str, viewer:str, username:str, name:str):
id = id.replace('profilePage_', '')
Expand All @@ -19,20 +21,30 @@ def from_username(username:str):
result = requests.get(request)
try:
data = result.json()
try:
user = data['graphql']['user']
profile = BaseProfile(
id=user['id'],
viewer=None,
username=user['username'],
name=user['full_name']
)
return profile
except:
raise InvalidInstaSchemaError(__name__)
except:
logger.error(f'Invalid request. Data: {result.raw}')
raise InvalidInstaRequestError(request)

try:
user = data['graphql']['user']
profile = BaseProfile(
id=user['id'],
viewer=None,
username=user['username'],
name=user['full_name']
)
return profile
except:
raise InvalidInstaSchemaError(__name__)

def username_profile(username:str):
return BaseProfile(
id=None,
viewer=None,
username=username,
name=None
)


def get_username(self):
return self.username
Expand Down
10 changes: 7 additions & 3 deletions instaclient/client/notiscraper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from instaclient.errors.common import InvalidNotificationTypeError, InvalidInstaSchemaError
from instaclient.errors.common import InvalidInstaRequestError, InvalidNotificationTypeError, InvalidInstaSchemaError
import json, requests
import types
from instaclient.client.urls import GraphUrls
Expand All @@ -25,7 +25,11 @@ def _scrape_notifications(self, source:int, viewer:int, types:list=None, count:i
notifications = []

# Map nodes into Notification Objects
viewer = BaseProfile.from_username(viewer)
try:
viewer = BaseProfile.from_username(viewer)
except InvalidInstaRequestError as error:
self.logger.error(f'InvalidInstaRequestError intercepted. Creating {viewer} profile with username.', exc_info=error)
viewer = BaseProfile.username_profile(viewer)
for node in nodes:
user = BaseProfile(
id=node['user']['id'],
Expand All @@ -46,7 +50,7 @@ def _scrape_notifications(self, source:int, viewer:int, types:list=None, count:i
def __scrape_nodes(self, source:str, types:list, count:int=None):
data = json.loads(source)
nodes = self.__parse_notifications(data)
self.logger.debug('NODE COUNT:\n{}'.format(len(nodes)))
self.logger.info('NODE COUNT: {}'.format(len(nodes)))

selected_nodes = []
for node in nodes:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
setup(
name = 'instaclient', # How you named your package folder (MyLib)
packages = find_packages(exclude=['tests, drivers']), # Chose the same as "name"
version = '2.1.8', # Start with a small number and increase it with every change you make
version = '2.1.9', # Start with a small number and increase it with every change you make
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description = 'Instagram client built with Python 3.8 and the Selenium package.',
long_description=README,
long_description_content_type="text/markdown",
author = 'David Wicker', # Type in your name
author_email = 'davidwickerhf@gmail.com', # Type in your E-Mail
url = 'https://github.com/wickerdevs/py-instaclient', # Provide either the link to your github or to your website
download_url = 'https://github.com/wickerdevs/py-instaclient/archive/v2.1.8.tar.gz', # I explain this later on
download_url = 'https://github.com/wickerdevs/py-instaclient/archive/v2.1.9.tar.gz', # I explain this later on
keywords = ['INSTAGRAM', 'BOT', 'INSTAGRAM BOT', 'INSTAGRAM CLIENT'], # Keywords that define your package best
install_requires=[ # I get to this in a second
'selenium',
Expand Down

0 comments on commit dc92bf4

Please sign in to comment.