def __init__(self):
     self.days_n_subscribers = []
     session = Session()
     channels = session.query(YTChannelSA).order_by(YTChannelSA.nname).all()
     self.channels = transpose_sqlalchs_to_ytvideopages(channels)
     session.close()
     self.loop_thru_channels()
def fetch_ytchannel_by_ytchannelid_n_transpose(ytchannelid, transposedobj):
    """
    The idea of transpose is to transfer the attributes from a SqlAlchemy object to a non-SqlAlchemy object
    It's done as a way to close the session inside function and have the object available with an open db-session
    (There may exist a better solution for this.)

    Notice:
      This function is a method in YtVideosPage in order to avoid importing to samodels
      To avoid direct-cross-importing (which results in crash/error) the adhoc test is in a different module.

  :param ytchannelid:
  :param transposedobj:
  :return:
  """
    transposed = False
    session = Session()
    ytchannel = session.query(samodels.YTChannelSA).filter(
        samodels.YTChannelSA.ytchannelid == ytchannelid).first()
    if ytchannel:
        transposedobj.transpose(ytchannel)
        transposed = True
    session.close()
    if transposed:
        return True
    return False
Example #3
0
def test_videos_per_day():
    session = Session()
    ytchannel = session.query(samodels.YTChannelSA). \
        filter(samodels.YTChannelSA.ytchannelid == 'ueduardoamoreira'). \
        first()
    print(ytchannel)
    print('get_videos_per_day', ytchannel.get_videos_per_day())
    session.close()
 def find_daily_subscribers(self):
     session = Session()
     dailysubs = session.query(YTDailySubscribersSA). \
         filter(YTDailySubscribersSA.ytchannelid == self.channel.ytchannelid). \
         order_by(YTDailySubscribersSA.infodate).all()
     # print('Channel', channel.nname, 'has', len(self.dailysubs), 'daily subscribers records.')
     if len(dailysubs) > 0:
         self.tabulate_subscribers_per_day(dailysubs)
     session.close()
def show_downloadables():
    session = Session()
    ytchannels = session.query(samodels.YTChannelSA).order_by(
        samodels.YTChannelSA.nname).all()
    total = len(ytchannels)
    n_of_dld = 0
    for ytchannel in ytchannels:
        isdld = ytchannel.is_downloadable_on_date()
        if isdld:
            n_of_dld += 1
        print(isdld, ' <== downloadable', ytchannel.nname)
    print(' ==       n_of_dld =', n_of_dld, 'total', total)
    session.close()
Example #6
0
 def dbfetch_each_n_days_dictlist():
     session = Session()
     ytchannels = session.\
         query(samodels.YTChannelSA). \
         order_by(samodels.YTChannelSA.nname). \
         all()
     dictlist = []
     for ytchannel in ytchannels:
         outdict = {
             'nname': ytchannel.nname,
             'each_n_days_for_dld': ytchannel.each_n_days_for_dld
         }
         dictlist.append(outdict)
     session.close()
     return dictlist
Example #7
0
 def show_dowloadables_at_moment():
     session = Session()
     ytchannels = session.query(samodels.YTChannelSA).all()
     outline = '\nshow_dowloadables\n'
     n_of_dlds = 0
     for i, ytchannel in enumerate(ytchannels):
         is_downloadable = ytchannel.is_downloadable_on_date()
         nextdate = ytchannel.find_next_download_date()
         print(i + 1, is_downloadable, nextdate, '<=',
               ytchannel.each_n_days_for_dld, '+', ytchannel.scrapedate,
               ytchannel.nname)
         if is_downloadable:
             n_of_dlds += 1
             outline += '%d %s to download \n' % (i + 1, ytchannel.nname)
     print(outline)
     if n_of_dlds == 0:
         print('=> no downloable pages for today.')
     else:
         print(n_of_dlds, 'downloable pages for today.')
Example #8
0
 def from_db_to_ytchannel(self):
   """
     Deactivated
   :return:
   """
   session = Session()
   if self.download_all_active_ones:
     dbytchannels = fetcher.fetch_all_active_ytchannels_in_db(session)
   else:
     dbytchannels = session.query(samodels.YTChannelSA). \
       order_by(samodels.YTChannelSA.nname). \
       all()
   for ytchannel in dbytchannels:
     if not ytchannel.is_downloadable_on_date():
       continue
     ytchannelpage = ytvidpagesMod.YtVideosPage(ytchannel.ytchannelid, ytchannel.nname)
     ytchannelpage.is_downloadable_on_date = True
     ytchannelpage.set_sname_by_nname()
     self.ytchannels.append(ytchannelpage)
   session.close()
Example #9
0
def list_todays_downloadables():
    """
    Deactivated
  :return:
  """
    session = Session()
    not_dld_counter = 0
    dld_counter = 0
    today = datetime.date.today()
    ytchannels = fetcher.fetch_all_active_ytchannels_in_db(session)
    for ytchannel in ytchannels:
        if not ytchannel.is_downloadable_on_date():
            not_dld_counter += 1
            # print(not_dld_counter, ytchannel.scrapedate, 'Not downloadable', ytchannel.nname)
            continue
        dld_counter += 1
        deltatime = today - ytchannel.scrapedate
        ndaysago = deltatime.days
        print(dld_counter, 'last dld on', ndaysago, 'days ago | dld on each',
              ytchannel.each_n_days_for_dld, 'days | nname', ytchannel.nname)
    session.close()
    print('dld_counter =', dld_counter, '| not_dld_counter = ',
          not_dld_counter)
Example #10
0
 def dbupdate_each_n_days_for_dld_from_dictlist(dictlist):
     n_update = 0
     session = Session()
     for each_n_days_dict in dictlist:
         ytchannel = session.query(samodels.YTChannelSA). \
           filter(samodels.YTChannelSA.nname == each_n_days_dict['nname']). \
           first()
         if ytchannel.each_n_days_for_dld != each_n_days_dict[
                 'each_n_days_for_dld']:
             ytchannel.each_n_days_for_dld = each_n_days_dict[
                 'each_n_days_for_dld']
             n_update += 1
             print(n_update, 'UPDATING ytchannel.each_n_days_for_dld =',
                   each_n_days_dict['each_n_days_for_dld'])
             session.commit()
     session.close()
     return n_update