pyshk package

Submodules

pyshk.api module

Library to provide access to MLKSHK API.

class pyshk.api.Api(consumer_key=None, consumer_secret=None, access_token_key=None, access_token_secret=None, base_url=None, testing=False)[source]

Bases: object

get_auth(redirect_uri=None)[source]
get_comments(sharekey=None)[source]

Retrieve comments on a SharedFile

Parameters:sharekey (str) – Sharekey for the file from which you want to return the set of comments.
Returns:List of Comment objects.
get_favorites(before=None, after=None)[source]

Get a list of the authenticated user’s 10 most recent favorites (likes).

Parameters:
  • before (str) – get 10 SharedFile objects before (but not including) the SharedFile given by before for the authenticated user’s set of Likes.
  • after (str) – get 10 SharedFile objects after (but not including) the SharedFile give by `after’ for the authenticated user’s set of Likes.
Returns:

List of SharedFile objects.

get_friends_shake(before=None, after=None)[source]

Contrary to the endpoint naming, this resource is for a list of SharedFiles from your friends on mlkshk.

Returns:List of SharedFiles.
get_incoming_shake(before=None, after=None)[source]

Returns a list of the most recent SharedFiles on mlkshk.com

Parameters:
  • before (str) – get 10 SharedFile objects before (but not including) the SharedFile given by before for the Incoming Shake.
  • after (str) – get 10 SharedFile objects after (but not including) the SharedFile give by `after’ for the Incoming Shake.
Returns:

List of SharedFile objects.

get_magic_shake(before=None, after=None)[source]

From the API:

Returns the 10 most recent files accepted by the ‘magic’ file selection algorithm. Currently any files with 10 or more likes are magic.

Returns:List of SharedFile objects
static get_nonce()[source]
get_shared_file(sharekey=None)[source]

Returns a SharedFile object given by the sharekey.

Parameters:sharekey (str) – Sharekey of the SharedFile you want to retrieve.
Returns:SharedFile
get_shared_files_from_shake(shake_id=None, before=None, after=None)[source]

Returns a list of SharedFile objects from a particular shake.

Parameters:
  • shake_id (int) – Shake from which to get a list of SharedFiles
  • before (str) – get 10 SharedFile objects before (but not including) the SharedFile given by before for the given Shake.
  • after (str) – get 10 SharedFile objects after (but not including) the SharedFile give by `after’ for the given Shake.
Returns:

List (list) of SharedFiles.

get_user(user_id=None, user_name=None)[source]

Get a user object from the API. If no user_id or user_name is specified, it will return the User object for the currently authenticated user.

Parameters:
  • user_id (int) – User ID of the user for whom you want to get information. [Optional]
  • user_name (str) – Username for the user for whom you want to get information. [Optional]
Returns:

A User object.

get_user_shakes()[source]

Get a list of Shake objects for the currently authenticated user.

Returns:A list of Shake objects.
like_shared_file(sharekey=None)[source]

‘Like’ a SharedFile. mlkshk doesn’t allow you to unlike a sharedfile, so this is ~~permanent~~.

Parameters:sharekey (str) – Sharekey for the file you want to ‘like’.
Returns:Either a SharedFile on success, or an exception on error.
post_comment(sharekey=None, comment=None)[source]

Post a comment on behalf of the current user to the SharedFile with the given sharekey.

Parameters:
  • sharekey (str) – Sharekey of the SharedFile to which you’d like to post a comment.
  • comment (str) – Text of the comment to post.
Returns:

Comment object.

post_shared_file(image_file=None, source_link=None, shake_id=None, title=None, description=None)[source]

Upload an image.

TODO: Don’t have a pro account to test (or even write) code to upload a shared filed to a particular shake.

Parameters:
  • image_file (str) – path to an image (jpg/gif) on your computer.
  • source_link (str) – URL of a source (youtube/vine/etc.)
  • shake_id (int) – shake to which to upload the file or source_link [optional]
  • title (str) – title of the SharedFile [optional]
  • description (str) – description of the SharedFile
Returns:

SharedFile key.

save_shared_file(sharekey=None)[source]

Save a SharedFile to your Shake.

Parameters:sharekey (str) – Sharekey for the file to save.
Returns:SharedFile saved to your shake.
update_shared_file(sharekey=None, title=None, description=None)[source]

Update the editable details (just the title and description) of a SharedFile.

Parameters:
  • sharekey (str) – Sharekey of the SharedFile to update.
  • title (Optional[str]) – Title of the SharedFile.
  • description (Optional[str]) – Description of the SharedFile
Returns:

SharedFile on success, 404 on Sharekey not found, 403 on unauthorized.

pyshk.errors module

exception pyshk.errors.ApiInstanceUnauthorized[source]

Bases: exceptions.Exception

exception pyshk.errors.ApiResponseUnauthorized(response)[source]

Bases: exceptions.Exception

Handle errors with authenticating the API instance

exception pyshk.errors.NotFound404(response)[source]

Bases: exceptions.Exception

Handle errors with 404 Not Found Status Codes

pyshk.models module

class pyshk.models.Comment(**kwargs)[source]

Bases: object

A class representing a Comment on mlkshk.

Exposes the following properties of a Comment:
comment.body comment.posted_at comment.user
AsDict(dt=True)[source]

A dict representation of this Comment instance.

The return value uses the same key names as the JSON representation.

Parameters:
  • dt (bool) – If True, return dates as python datetime objects. If
  • return dates as ISO strings. (False,) –
Returns:

A dict representing this Comment instance

AsJsonString()[source]

A JSON string representation of this Comment instance.

Returns:A JSON string representation of this Comment instance
static NewFromJSON(data)[source]

Create a new Comment instance from a JSON dict.

Parameters:data (dict) – JSON dictionary representing a Comment.
Returns:A Comment instance.
__repr__()[source]

String representation of this Comment instance.

class pyshk.models.Shake(**kwargs)[source]

Bases: object

A class representing a Shake on mlkshk.

Exposes the following properties of a Shake:
shake.id shake.name shake.owner shake.url shake.thumbnail_url shake.description shake.type shake.created_at shake.updated_at
AsDict(dt=True)[source]

A dict representation of this Shake instance.

The return value uses the same key names as the JSON representation.

Returns:A dict representing this Shake instance
AsJsonString()[source]

A JSON string representation of this Shake instance.

Returns:A JSON string representation of this Shake instance
static NewFromJSON(data)[source]

Create a new Shake instance from a JSON dict.

Parameters:data (dict) – JSON dictionary representing a Shake.
Returns:A Shake instance.
__repr__()[source]

String representation of this Shake instance.

created_at
created_at_iso
updated_at
updated_at_iso
class pyshk.models.SharedFile(*args, **kwargs)[source]

Bases: object

A class representing a file shared on MLKSHK.

Exposes the following properties of a sharedfile:
sharedfile.sharekey sharedfile.name sharedfile.user sharedfile.title sharedfile.description sharedfile.posted_at sharedfile.permalink sharedfile.width sharedfile.height sharedfile.views sharedfile.likes sharedfile.saves sharedfile.comments sharedfile.nsfw sharedfile.image_url sharedfile.source_url sharedfile.saved sharedfile.liked
Parameters:
  • sharedfile.sharekey
  • sharedfile.name
  • sharedfile.user
  • sharedfile.title
  • sharedfile.description
  • sharedfile.posted_at
  • sharedfile.permalink
  • sharedfile.width
  • sharedfile.height
  • sharedfile.views
  • sharedfile.likes
  • sharedfile.saves
  • sharedfile.comments
  • sharedfile.nsfw
  • sharedfile.image_url
  • sharedfile.source_url
  • sharedfile.saved
  • sharedfile.liked
AsDict(dt=True)[source]

A dict representation of this Shake instance.

The return value uses the same key names as the JSON representation.

Parameters:dt (bool) – If True, return dates as python datetime objects. If False, return dates as ISO strings.
Returns:A dict representing this Shake instance
AsJsonString()[source]

A JSON string representation of this SharedFile instance.

Returns:A JSON string representation of this SharedFile instance
static NewFromJSON(data)[source]

Create a new SharedFile instance from a JSON dict.

Parameters:data (dict) – JSON dictionary representing a SharedFile.
Returns:A SharedFile instance.
__eq__(other)[source]

Compare two SharedFiles on all attributes except saved status and liked status.

posted_at
posted_at_iso
class pyshk.models.User(**kwargs)[source]

Bases: object

A class representing a MLKSHK user.

Exposes the following properties of a user:
user.id user.name user.profile_image_url user.about user.website user.shakes
AsDict(dt=True)[source]

A dict representation of this User instance.

The return value uses the same key names as the JSON representation.

Parameters:
  • dt (bool) – If True, return dates as python datetime objects. If
  • return dates as ISO strings. (False,) –
Returns:

A dict representing this User instance

AsJsonString()[source]

A JSON string representation of this User instance.

Returns:A JSON string representation of this User instance
static NewFromJSON(data)[source]

Create a new User instance from a JSON dict.

Parameters:data (dict) – JSON dictionary representing a user.
Returns:A User instance.
__eq__(other)[source]

Compare two user objects against one another.

Parameters:other (User) – another User object against which to compare the current user.
__repr__()[source]

String representation of this User instance.

mlkshk_url
shake_count
pyshk.models.convert_time(dt)[source]

2015-10-09T15:58:11Z -> datetime.datetime(2015, 10, 9, 15, 58, 11)

Module contents