collecting.py module for working with Tweepy

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I have a module collection.py that functions as a tool to collect tweets using tweepy. It has two classes : Authentication and Collection.



Authentication class will create an object that acts as a starting point to collect data from twitter. An instance of this will the an argument for Collection.



Collection class will create a 'collection' object, it has different methods on how to collect the data, by Collect_object.collect(method = ...), through home_timeline, through Cursor(api.home_timeline, ....), and also through user_timeline.



I would like to know how to design better, and using better techniques. (for functionality, readability, compactness, and becoming a library)



Below are the code and usage example.




collection.py:



import tweepy
from tweepy import OAuthHandler
import numpy
import datetime



class Authentication(object):

def __init__(self, consumer_key, consumer_secret, access_token, access_secret):

self.consumer_key = consumer_key
self.consunmer_secret = consumer_secret
self.access_token = access_token
self.access_secret = access_secret

self.auth = OAuthHandler(consumer_key, consumer_secret)
self.auth.set_access_token(access_token, access_secret)
self.api = tweepy.API(self.auth)


class Collection(object):

def __init__(self, auth_object):

self.auth_object = auth_object
self.api = self.auth_object.api
self.collection =

def collect_home(self, method = 'Default', n = 20, **kwargs):

if method == 'Default':

public_stats = self.api.home_timeline()

if method == 'Cursor':

public_stats = tweepy.Cursor(self.api.home_timeline, **kwargs).items(n)

self.stats = [stat for stat in public_stats]
self.collection.extend(self.stats)

date = datetime.datetime.now()
time = date.timetuple()
year = time.tm_year
month = time.tm_mon
day = time.tm_mday
hour = time.tm_hour
mnt = time.tm_min
time_string = 'hour_min___date___'.format(
str(hour), str(mnt), str(day), str(month), str(year))
self.time_collected = time_string;

return self.stats, self.time_collected

def collect_user(self, username, n = 20, **kwargs):

user_stats = tweepy.Cursor(self.api.user_timeline,
screen_name = username, **kwargs).items(n)

self.stats = [stat for stat in user_stats]
self.collection.extend(self.stats)

date = datetime.datetime.now()
time = date.timetuple()
year = time.tm_year
month = time.tm_mon
day = time.tm_mday
hour = time.tm_hour
mnt = time.tm_min
time_string = 'hour_min___date___'.format(
str(hour), str(mnt), str(day), str(month), str(year))
self.time_collected = time_string;

return self.stats, self.time_collected

def save(self, *args, **kwargs):
numpy.save(*args, **kwargs)



Usage example :



consumer_key = '...............................'
consumer_secret = '...............................'
access_token = '...............................'
access_secret = '..............................'

Init = Authentication(consumer_key, consumer_secret, access_token, access_secret)
Collect = Collection(Init)

Collect.collect_user('Reuters', n = 50)
Collect.collect_user('anbarief', n = 50)

data = Collect.collection






share|improve this question



























    up vote
    2
    down vote

    favorite












    I have a module collection.py that functions as a tool to collect tweets using tweepy. It has two classes : Authentication and Collection.



    Authentication class will create an object that acts as a starting point to collect data from twitter. An instance of this will the an argument for Collection.



    Collection class will create a 'collection' object, it has different methods on how to collect the data, by Collect_object.collect(method = ...), through home_timeline, through Cursor(api.home_timeline, ....), and also through user_timeline.



    I would like to know how to design better, and using better techniques. (for functionality, readability, compactness, and becoming a library)



    Below are the code and usage example.




    collection.py:



    import tweepy
    from tweepy import OAuthHandler
    import numpy
    import datetime



    class Authentication(object):

    def __init__(self, consumer_key, consumer_secret, access_token, access_secret):

    self.consumer_key = consumer_key
    self.consunmer_secret = consumer_secret
    self.access_token = access_token
    self.access_secret = access_secret

    self.auth = OAuthHandler(consumer_key, consumer_secret)
    self.auth.set_access_token(access_token, access_secret)
    self.api = tweepy.API(self.auth)


    class Collection(object):

    def __init__(self, auth_object):

    self.auth_object = auth_object
    self.api = self.auth_object.api
    self.collection =

    def collect_home(self, method = 'Default', n = 20, **kwargs):

    if method == 'Default':

    public_stats = self.api.home_timeline()

    if method == 'Cursor':

    public_stats = tweepy.Cursor(self.api.home_timeline, **kwargs).items(n)

    self.stats = [stat for stat in public_stats]
    self.collection.extend(self.stats)

    date = datetime.datetime.now()
    time = date.timetuple()
    year = time.tm_year
    month = time.tm_mon
    day = time.tm_mday
    hour = time.tm_hour
    mnt = time.tm_min
    time_string = 'hour_min___date___'.format(
    str(hour), str(mnt), str(day), str(month), str(year))
    self.time_collected = time_string;

    return self.stats, self.time_collected

    def collect_user(self, username, n = 20, **kwargs):

    user_stats = tweepy.Cursor(self.api.user_timeline,
    screen_name = username, **kwargs).items(n)

    self.stats = [stat for stat in user_stats]
    self.collection.extend(self.stats)

    date = datetime.datetime.now()
    time = date.timetuple()
    year = time.tm_year
    month = time.tm_mon
    day = time.tm_mday
    hour = time.tm_hour
    mnt = time.tm_min
    time_string = 'hour_min___date___'.format(
    str(hour), str(mnt), str(day), str(month), str(year))
    self.time_collected = time_string;

    return self.stats, self.time_collected

    def save(self, *args, **kwargs):
    numpy.save(*args, **kwargs)



    Usage example :



    consumer_key = '...............................'
    consumer_secret = '...............................'
    access_token = '...............................'
    access_secret = '..............................'

    Init = Authentication(consumer_key, consumer_secret, access_token, access_secret)
    Collect = Collection(Init)

    Collect.collect_user('Reuters', n = 50)
    Collect.collect_user('anbarief', n = 50)

    data = Collect.collection






    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a module collection.py that functions as a tool to collect tweets using tweepy. It has two classes : Authentication and Collection.



      Authentication class will create an object that acts as a starting point to collect data from twitter. An instance of this will the an argument for Collection.



      Collection class will create a 'collection' object, it has different methods on how to collect the data, by Collect_object.collect(method = ...), through home_timeline, through Cursor(api.home_timeline, ....), and also through user_timeline.



      I would like to know how to design better, and using better techniques. (for functionality, readability, compactness, and becoming a library)



      Below are the code and usage example.




      collection.py:



      import tweepy
      from tweepy import OAuthHandler
      import numpy
      import datetime



      class Authentication(object):

      def __init__(self, consumer_key, consumer_secret, access_token, access_secret):

      self.consumer_key = consumer_key
      self.consunmer_secret = consumer_secret
      self.access_token = access_token
      self.access_secret = access_secret

      self.auth = OAuthHandler(consumer_key, consumer_secret)
      self.auth.set_access_token(access_token, access_secret)
      self.api = tweepy.API(self.auth)


      class Collection(object):

      def __init__(self, auth_object):

      self.auth_object = auth_object
      self.api = self.auth_object.api
      self.collection =

      def collect_home(self, method = 'Default', n = 20, **kwargs):

      if method == 'Default':

      public_stats = self.api.home_timeline()

      if method == 'Cursor':

      public_stats = tweepy.Cursor(self.api.home_timeline, **kwargs).items(n)

      self.stats = [stat for stat in public_stats]
      self.collection.extend(self.stats)

      date = datetime.datetime.now()
      time = date.timetuple()
      year = time.tm_year
      month = time.tm_mon
      day = time.tm_mday
      hour = time.tm_hour
      mnt = time.tm_min
      time_string = 'hour_min___date___'.format(
      str(hour), str(mnt), str(day), str(month), str(year))
      self.time_collected = time_string;

      return self.stats, self.time_collected

      def collect_user(self, username, n = 20, **kwargs):

      user_stats = tweepy.Cursor(self.api.user_timeline,
      screen_name = username, **kwargs).items(n)

      self.stats = [stat for stat in user_stats]
      self.collection.extend(self.stats)

      date = datetime.datetime.now()
      time = date.timetuple()
      year = time.tm_year
      month = time.tm_mon
      day = time.tm_mday
      hour = time.tm_hour
      mnt = time.tm_min
      time_string = 'hour_min___date___'.format(
      str(hour), str(mnt), str(day), str(month), str(year))
      self.time_collected = time_string;

      return self.stats, self.time_collected

      def save(self, *args, **kwargs):
      numpy.save(*args, **kwargs)



      Usage example :



      consumer_key = '...............................'
      consumer_secret = '...............................'
      access_token = '...............................'
      access_secret = '..............................'

      Init = Authentication(consumer_key, consumer_secret, access_token, access_secret)
      Collect = Collection(Init)

      Collect.collect_user('Reuters', n = 50)
      Collect.collect_user('anbarief', n = 50)

      data = Collect.collection






      share|improve this question













      I have a module collection.py that functions as a tool to collect tweets using tweepy. It has two classes : Authentication and Collection.



      Authentication class will create an object that acts as a starting point to collect data from twitter. An instance of this will the an argument for Collection.



      Collection class will create a 'collection' object, it has different methods on how to collect the data, by Collect_object.collect(method = ...), through home_timeline, through Cursor(api.home_timeline, ....), and also through user_timeline.



      I would like to know how to design better, and using better techniques. (for functionality, readability, compactness, and becoming a library)



      Below are the code and usage example.




      collection.py:



      import tweepy
      from tweepy import OAuthHandler
      import numpy
      import datetime



      class Authentication(object):

      def __init__(self, consumer_key, consumer_secret, access_token, access_secret):

      self.consumer_key = consumer_key
      self.consunmer_secret = consumer_secret
      self.access_token = access_token
      self.access_secret = access_secret

      self.auth = OAuthHandler(consumer_key, consumer_secret)
      self.auth.set_access_token(access_token, access_secret)
      self.api = tweepy.API(self.auth)


      class Collection(object):

      def __init__(self, auth_object):

      self.auth_object = auth_object
      self.api = self.auth_object.api
      self.collection =

      def collect_home(self, method = 'Default', n = 20, **kwargs):

      if method == 'Default':

      public_stats = self.api.home_timeline()

      if method == 'Cursor':

      public_stats = tweepy.Cursor(self.api.home_timeline, **kwargs).items(n)

      self.stats = [stat for stat in public_stats]
      self.collection.extend(self.stats)

      date = datetime.datetime.now()
      time = date.timetuple()
      year = time.tm_year
      month = time.tm_mon
      day = time.tm_mday
      hour = time.tm_hour
      mnt = time.tm_min
      time_string = 'hour_min___date___'.format(
      str(hour), str(mnt), str(day), str(month), str(year))
      self.time_collected = time_string;

      return self.stats, self.time_collected

      def collect_user(self, username, n = 20, **kwargs):

      user_stats = tweepy.Cursor(self.api.user_timeline,
      screen_name = username, **kwargs).items(n)

      self.stats = [stat for stat in user_stats]
      self.collection.extend(self.stats)

      date = datetime.datetime.now()
      time = date.timetuple()
      year = time.tm_year
      month = time.tm_mon
      day = time.tm_mday
      hour = time.tm_hour
      mnt = time.tm_min
      time_string = 'hour_min___date___'.format(
      str(hour), str(mnt), str(day), str(month), str(year))
      self.time_collected = time_string;

      return self.stats, self.time_collected

      def save(self, *args, **kwargs):
      numpy.save(*args, **kwargs)



      Usage example :



      consumer_key = '...............................'
      consumer_secret = '...............................'
      access_token = '...............................'
      access_secret = '..............................'

      Init = Authentication(consumer_key, consumer_secret, access_token, access_secret)
      Collect = Collection(Init)

      Collect.collect_user('Reuters', n = 50)
      Collect.collect_user('anbarief', n = 50)

      data = Collect.collection








      share|improve this question












      share|improve this question




      share|improve this question








      edited Mar 24 at 15:00









      200_success

      123k14142399




      123k14142399









      asked Mar 24 at 14:48









      Arief

      420112




      420112

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f190372%2fcollecting-py-module-for-working-with-tweepy%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f190372%2fcollecting-py-module-for-working-with-tweepy%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Python Lists

          Aion

          JavaScript Array Iteration Methods