コード例 #1
0
ファイル: main.py プロジェクト: danylo-dudok/youtube-rss
def main(arguments: List[str]):
    channel_ids = read_argument(arguments, CHANNEL_ARGUMENT_PREFIX)
    channels_file_path = read_argument(arguments, LOCATION_ARGUMENT_PREFIX)
    if not channels_file_path and not channel_ids:
        raise Exception('Invalid input arguments')

    ids = channel_ids.replace(' ', '').replace('[', '').replace(']', '').split(',')\
        if channel_ids else read_channels(channels_file_path)
    last_check = read_argument(arguments, LAST_CHECK_ARGUMENT_PREFIX)
    last_check = str_to_date(last_check) if last_check else DEFAULT_LAST_CHECK
    channels = get_channels(ids, last_check)

    posts_count = 0
    dict_channels = []
    for channel in channels:
        dict_channels.append(dataclasses.asdict(channel))
        posts_count += len(channel.posts)

    print(serialize({
        'amount': posts_count,
        'channels': dict_channels,
    }))
コード例 #2
0
ファイル: operation.py プロジェクト: ThomasMarcel/ana-tool
	def get(self):
		self.response.headers['Content-Type'] = 'application/json'

		# Duplicate tickets that are not yearly
		if self.request.get('direction') in ['in', 'out']:
			url = '%s%s/api/operation/list?direction=%s&target=%s' % (config.PROTOCOL, config.APP_HOSTNAME, self.request.get('direction'), self.request.get('target'))
		else:
			url = '%s%s/api/operation/list?target=%s' % (config.PROTOCOL, config.APP_HOSTNAME, self.request.get('target'))

		result = urlfetch.fetch(url)
		if result.status_code == 200:
			operationlist = json.loads(result.content)
		else:
			operationlist = []

                index = 0
                operationlist_recurrent = []
                for operation in operationlist:
                        logging.warning('DEBUG CNOperations - operation[frequency]: %s' % operation['frequency'])
			if operation['frequency'] == 'once':
	                        operationdict = {'key': operation['key'], 'sequence': 0, 'type': operation['type'], 'name': operation['name'], 'target': operation['target'], 'amount': operation['amount'], 'frequency': operation['frequency'], 'cutoff_date': operation['cutoff_date'], 'delay_raise': operation['delay_raise'], 'created': operation['created'], 'updated': operation['updated']}
                        elif operation['frequency'] == 'monthly':
                                first_seq_year = str(PERIOD_START.year)
                                first_seq_month = str(PERIOD_START.month)
                                if len(first_seq_month) == 1:
                                        first_seq_month = '0' + first_seq_month
                                #first_seq_day = str(PERIOD_START.day)
                                first_seq_day = str(operation['cutoff_date'][0]['day'])
                                if len(first_seq_day) == 1:
                                        first_seq_day = '0' + first_seq_day
                                first_seq_date = tools.str_to_date(first_seq_year + first_seq_month + first_seq_day)
                                if first_seq_date < PERIOD_START:
                                        logging.warning('DEBUG CNOperations - first_seq_date (%s) < PERIOD_START (%s)' % (str(first_seq_date), str(PERIOD_START)))
                                        first_seq_date = tools.date_operation(first_seq_date, 'month', 1)
                                else:
                                        logging.warning('DEBUG CNOperations - first_seq_date (%s) > PERIOD_START (%s)' % (str(first_seq_date), str(PERIOD_START)))
                                logging.warning('DEBUG CNBalance - first_seq_date: %s' %  first_seq_date)

                                #operationlist.pop(index)
                                seq = 0
                                while first_seq_date < tools.date_operation(datetime.now(), 'month', 1):
                                        operationdict = {'key': operation['key'], 'sequence': seq, 'name': operation['name'], 'target_kind': operation['target_kind'], 'target': operation['target'], 'amount': operation['amount'], 'frequency': operation['frequency'], 'cutoff_date': {'day': first_seq_date.day, 'month': first_seq_date.month, 'year': first_seq_date.year}, 'delay_raise': operation['delay_raise'], 'created': operation['created'], 'updated': operation['updated']}
                                        month = str(first_seq_date.month)
                                        if len(month) < 2:
                                                month = '0' + month
                                        day = str(first_seq_date.day)
                                        if len(day) < 2:
                                                day = '0' + day
                                        operationdict['cutoff_date_int'] = int(str(first_seq_date.year) + month + day)
                                        operationdict['cutoff_date_unix'] = time.mktime(tools.str_to_date(str(first_seq_date.year) + month + day).timetuple())
                                        operationlist_recurrent.append(operationdict)
                                        first_seq_date = tools.date_operation(first_seq_date, 'month', 1)
                                        logging.warning('DEBUG CNOperations - first_seq_date: %s' %  first_seq_date)
                                        seq += 1

			else:
                                logging.warning('DEBUG CNOperations - operation[frequency] (%s) != monthly' % operation['frequency'])
                                #operationlist.pop(index)
                                seq = 0
                                for date in operation['cutoff_date']:
                                        logging.warning('DEBUG CNOperations - date in operation[cutoff_date](%s): %s' % (str(operation['cutoff_date']), str(date)))
                                        try:
                                                cutoff_year = date['year']
                                        except KeyError:
                                                if date['month'] < PERIOD_START.month or (date['month'] == PERIOD_START.month and date['day'] < PERIOD_START):
                                                        date['year'] = PERIOD_END.year
                                                else:
                                                        date['year'] = PERIOD_START.year
                                        operation_singledate = operation
                                        operation_singledate['sequence'] = seq

                                        month = str(date['month'])
                                        if len(month) < 2:
                                                month = '0' + month
                                        day = str(date['day'])
                                        if len(day) < 2:
                                                day = '0' + day
                                        operation_singledate['cutoff_date'] = {'day': date['day'], 'month': date['month'], 'year': date['year']}
                                        operation_singledate['cutoff_date_int'] = int(str(date['year']) + month + day)
                                        operation_singledate['cutoff_date_unix'] = time.mktime(tools.str_to_date(str(date['year']) + month + day).timetuple())
                                        logging.warning('DEBUG CNOperations - operation_singledate: %s' % str(operation_singledate))
                                        operationlist_recurrent.append(operation_singledate)
                                        seq += 1

                        index += 1

                operationlist = sorted(operationlist_recurrent, key=lambda k: k['cutoff_date_unix'])
                previous = None
                index = 0
                for operation in operationlist:
                        if previous is not None and index > 0:
                                if previous['cutoff_date_unix'] == operation['cutoff_date_unix'] and previous['frequency'] != 'yearly' and operation['frequency'] == 'yearly':
                                        temp = previous
                                        operationlist[index - 1] = operation
                                        operationlist[index] = temp
                        previous = operation
                        index += 1


                #logging.warning('DEBUG CNBalance - operationlist: %s' % str(operationlist))

                self.response.write(json.dumps(operationlist))
コード例 #3
0
ファイル: operation.py プロジェクト: ThomasMarcel/ana-tool
import urllib2
from datetime import datetime
import time

from google.appengine.ext import ndb
from google.appengine.api import urlfetch
from google.appengine.api import mail

import config
import tools
from user.models import User
from cn.models import CN
from organization.models import Organization, OU
from models import Operation, CustomOperation

PERIOD_START = tools.str_to_date('20130819')
PERIOD_END = tools.str_to_date('20140715')

class OperationSet(webapp2.RequestHandler):
	def get(self):

		self.response.headers['Content-Type'] = 'application/json'

		new = False
		custom = False
		if len(self.request.get('parent')) > 0:
			custom = True

		if len(self.request.get('operation')) > 0:
			if custom:
				operation = CustomOperation.get_by_key(self.request.get('operation'))
コード例 #4
0
def transform_rss_entry_to_post(entry: Dict) -> YoutubePost:
    return YoutubePost(
        url=entry['link'],
        title=entry['title'],
        published=str_to_date(entry['published']),
    )