Skip to content

Commit

Permalink
Docstring Fixes Jul 12 i ve had enough
Browse files Browse the repository at this point in the history
  • Loading branch information
TDKorn committed Jul 19, 2022
1 parent c1a5540 commit 91ce8af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
9 changes: 5 additions & 4 deletions InstaTweet/instaclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def __init__(self, session_id: str, user_agent: str = None, proxies: dict = None
"""Minimalistic class for scraping/downloading Instagram user/media data
:param session_id: valid Instagram sessionid cookie from a browser
:param user_agent: user agent to use in requests made by the class
:param user_agent: user agent to use for requests made by the class
:param proxies: proxies to use for requests made by the class
"""
if not isinstance(session_id, str):
raise TypeError('session_id must be a string')
Expand All @@ -19,7 +20,7 @@ def __init__(self, session_id: str, user_agent: str = None, proxies: dict = None
self.proxies = proxies

def request(self, url: str) -> requests.Response:
"""Sends a request using the :attr:`cookies`, :attr:`headers`, and :ivar:`proxies`
"""Sends a request using the :attr:`cookies`, :attr:`headers`, and :attr:`proxies`
:param url: the Instagram URL to send the request to
"""
Expand Down Expand Up @@ -78,11 +79,11 @@ def download_post(self, post: InstaPost, filepath: str = None) -> bool:
return True

@property
def headers(self):
def headers(self) -> dict:
"""Headers to use in :meth:`.~request`"""
return {'User-Agent': self.user_agent, }

@property
def cookies(self):
def cookies(self) -> dict:
"""Cookies to use in :meth:`.~request`"""
return {'sessionid': self.session_id, }
34 changes: 19 additions & 15 deletions InstaTweet/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@ class Profile:
def __init__(self, name: str = 'default', local: bool = True, **kwargs):
"""Create a new profile
A :class:`Profile` contains a user map and all API access settings associated with it.
The user map keeps track of previously scraped posts, which is then used to determine which posts are new
A :class:`Profile` contains a ``user_map`` and all API access settings associated with it
Note that a name is not necessary to create and *InstaTweet* a profile, but it's required to save one
The ``user_map`` is a mapping of added Instagram usernames and their associated lists of hashtags,
scraped posts, and sent tweets. The ``scraped`` list is used to determine which posts are new when InstaTweeting
:param name: unique profile name
:param local: if True, pickle files will save to the :attr:`~.LOCAL_DIR`. Otherwise, will save to a Postgres DB
:param local: if ``True``, saving will use a file in the :attr:`~.LOCAL_DIR`. Otherwise, will save to a database
:param kwargs: see below
:Keyword Arguments:
* *session_id* (``str``) --
Instagram ``sessionid`` cookie, obtained by logging in through browser
Instagram ``sessionid`` cookie, obtained by logging in through browser
* *twitter_keys* (``dict``) --
Twitter API Keys with v1.1 endpoint access
* See :attr:`~TweetClient.DEFAULT_KEYS` for a template
Twitter API Keys with v1.1 endpoint access
* See :attr:`~InstaTweet.tweetclient.TweetClient.DEFAULT_KEYS` for a template
* *user_agent* (``str``) -- Optional
The user agent to use for requests; scrapes the newest Chrome agent if not provided
The user agent to use for requests; scrapes the newest Chrome agent if not provided
* *proxy_key* (``str``) -- Optional
Name of environment variable to retrieve proxies from
Name of environment variable to retrieve proxies from
* *user_map* (``dict``) -- Optional
A dict of Instagram users and their associated :cvar:`~.USER_MAPPING`
A dict of Instagram users and their associated :attr:`~.USER_MAPPING`
:Note:
A name is not necessary to create and *InstaTweet* a profile, but it's required to :meth:`~.save` it
"""
self.local = local
self.name = name # Will raise Exception if name is already used
Expand Down Expand Up @@ -138,9 +142,9 @@ def add_hashtags(self, user: str, hashtags: Iterable):
print(f'Added hashtags for @{user}')

def save(self, name: str = None, alert: bool = True) -> bool:
"""Saves the Profile as a pickled object, using the specified or currently set name.
"""Pickles and saves the :class:`Profile` using the specified or currently set name.
:param name: name to save the profile under; replaces the current name
:param name: name to save the :class:`Profile` under; replaces the current :attr:`~.name`
:param alert: set to ``True`` to print a message upon successful save
"""
if name:
Expand All @@ -163,7 +167,7 @@ def _save_profile(self, alert: bool = True) -> bool:
return db.save_profile(profile=self, alert=alert)

def validate(self) -> None:
"""Checks to see if the profile is fully configured for InstaTweeting
"""Checks to see if the Profile is fully configured for InstaTweeting
:raises ValueError: if the :attr:`~.session_id`, :attr:`~.twitter_keys`, or :attr:`~.user_map` are invalid
"""
Expand Down Expand Up @@ -276,7 +280,7 @@ def name(self, profile_name):
def session_id(self) -> str:
"""Instagram ``sessionid`` cookie, obtained by logging in through a browser
:Tip: Log in to a browser you don't use to make sure your session doesn't change
:Tip: If you log into your account with a browser you don't use, the session cookie will last longer
"""
return self._session_id

Expand All @@ -292,7 +296,7 @@ def session_id(self, session_id: str):

@property
def twitter_keys(self) -> dict:
"""Twitter developer API keys with v1.1 endpoint access. See :attr:`TweetClient.DEFAULT_KEYS`"""
"""Twitter developer API keys with v1.1 endpoint access. See :attr:`~.DEFAULT_KEYS`"""
return self._twitter_keys

@twitter_keys.setter
Expand Down
6 changes: 5 additions & 1 deletion InstaTweet/tweetclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, profile: InstaTweet.Profile, proxies: dict = None):
Basically just a wrapper for tweepy. It uses the settings of a profile to initialize the API and send tweets
:param profile: the profile to use when initializing a :class:`tweepy.API` object
:param proxies: optional proxies to use (
:param proxies: optional proxies to use when making API requests
"""
self.profile = profile
self.proxies = proxies
Expand All @@ -41,6 +41,10 @@ def get_api(self) -> tweepy.API:

@staticmethod
def get_oauth(api_keys: dict) -> tweepy.OAuth1UserHandler:
"""Initializes and returns an ``OAuth1UserHandler`` object from tweepy using the provided API keys
:param api_keys: Twitter developer API keys with v1.1 endpoint access
"""
if missing_keys := [key for key in TweetClient.DEFAULT_KEYS if key not in api_keys]:
raise KeyError(
f"Missing the following Twitter Keys: {missing_keys}"
Expand Down

0 comments on commit 91ce8af

Please sign in to comment.