Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Code cleanup #349

Closed
wants to merge 10 commits into from
Closed

Code cleanup #349

wants to merge 10 commits into from

Conversation

xen
Copy link

@xen xen commented Oct 5, 2017

What I purpose with this PR:

  • Code simplification, it is little messed in IDE when you see all methods twice
  • PEP8 cleanup
  • Switch to mixin type of inheritance

I hope it will help to maintain and develop code in the future.

@sudoguy sudoguy self-requested a review October 5, 2017 12:27
Copy link
Collaborator

@sudoguy sudoguy left a comment

Choose a reason for hiding this comment

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

Wrong method resolution order. Method super() can't find right function


class Bot(API):
class Bot(API, BotArchive, BotBlock, BotComment, BotDelete,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong method resolution order. API must be in end

super(Bot, self).__init__()

stop_words=None):
super(self.__class__, self).__init__()
Copy link
Collaborator

Choose a reason for hiding this comment

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

API init

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not self.__class__

delay.small_delay(self)
media = self.get_media_info(media_id)
media = media[0] if isinstance(media, list) else media
if super(self.__class__, self).archiveMedia(media, undo):
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

return False
if limits.check_if_bot_can_block(self):
delay.block_delay(self)
if super(self.__class__, self).block(user_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

user_id = self.convert_to_user_id(user_id)
if limits.check_if_bot_can_unblock(self):
delay.unblock_delay(self)
if super(self.__class__, self).unblock(user_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

class BotPhoto(object):
def upload_photo(self, photo, caption=None, upload_id=None):
delay.small_delay(self)
if super(self.__class__, self).uploadPhoto(photo, caption, upload_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

caption = media['caption']['text']
with open('{path}{0}_{1}.txt'.format(media['user']['username'], media_id, path=path), encoding='utf8', mode='w') as f:
f.write(caption)
photo = super(self.__class__, self).downloadPhoto(
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

return True # whitelisted user
if limits.check_if_bot_can_unfollow(self):
delay.unfollow_delay(self)
if super(self.__class__, self).unfollow(user_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

def unlike(self, media_id):
if limits.check_if_bot_can_unlike(self):
delay.unlike_delay(self)
if super(self.__class__, self).unlike(media_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

def upload_video(self, video, thumbnail, caption=''):
delay.small_delay(self)
self.logger.info("Started uploading '{video}'".format(video=video))
if not super(self.__class__, self).uploadVideo(video, thumbnail, caption):
Copy link
Collaborator

Choose a reason for hiding this comment

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

API class method

@ohld
Copy link
Owner

ohld commented Oct 15, 2017

@xen Will you fix the issues with the super class? Your pull request is awesome but there are several bugs that should be fixed!

@ohld
Copy link
Owner

ohld commented Oct 18, 2017

@xen Waiting for your fixes.

@ohld ohld closed this Oct 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants