Пример #1
0
 def to_jalali(self, _format="%Y/%m/%d"):
     if self.inp_type == datetime.datetime:
         if _format:
             return khayyam.JalaliDatetime(self.inp).strftime(_format)
         else:
             return khayyam.JalaliDatetime(self.inp)
     elif self.inp_type == datetime.date:
         if _format:
             return khayyam.JalaliDatetime(self.inp).strftime(_format)
         else:
             return khayyam.JalaliDatetime(self.inp)
Пример #2
0
 def get_all(self, _page=1, _size=20):
     try:
         __body = {}
         r = MongodbModel(collection='news_report_broken',
                          body=__body,
                          page=_page,
                          size=_size).get_all_pagination()
         ls = []
         for i in r:
             i['date'] = khayyam.JalaliDatetime(
                 i['date']).strftime('%Y/%m/%d %H:%M:%S')
             try:
                 i['full_name'] = UserModel(
                     _id=i['user']).get_one()['value']['full_name']
             except:
                 i['full_name'] = ''
             ls.append(i)
         self.result['value'] = ls
         self.result['status'] = True
         return self.result
     except:
         Debug.get_exception(sub_system='admin',
                             severity='error',
                             tags='mongodb > get_all',
                             data='collection > news_report_broken')
         return self.result
Пример #3
0
 def search(self, name, date, _type, manual, count_bolton_section,
            bolton_types):
     try:
         __body = {"$and": []}
         if name != '':
             __body['$and'].append({'name': {"$regex": '^' + name}})
         if date != '':
             start_date = khayyam.JalaliDatetime().strptime(
                 date + " 00:00:00", "%Y/%m/%d %H:%M:%S").todatetime()
             end_date = khayyam.JalaliDatetime().strptime(
                 date + " 23:59:59", "%Y/%m/%d %H:%M:%S").todatetime()
             __body['$and'].append(
                 {'date': {
                     "$gte": start_date,
                     "$lt": end_date
                 }})
         if _type != '':
             __body['$and'].append({'type': ObjectId(_type)})
         if manual != '':
             __body['$and'].append({'manual': manual})
         if count_bolton_section != '':
             __body['$and'].append(
                 {'sections': {
                     "$size": int(count_bolton_section)
                 }})
         if not len(__body['$and']):
             __body = {}
         all_bolton = MongodbModel(collection='bolton',
                                   body=__body).get_all()
         self.result['value'] = []
         for i in all_bolton:
             self.result['value'].append(self.get_bolton(bolton_types, i))
         self.result['status'] = True
         return self.result
     except:
         print Debug.get_exception(sub_system='admin',
                                   severity='error',
                                   tags='mongodb > save',
                                   data='collection > bolton')
         return self.result
Пример #4
0
 def get_query(self, q):
     self.value.append(
         dict(
             id=q['_id'],
             index=q['index'],
             doc_type=q['doc_type'],
             body=json.dumps(q['body']),
             item_id=q['item_id'],
             result=json.dumps(q['result']),
             function=q['function'],
             date=khayyam.JalaliDatetime(
                 q['date']).strftime('%Y/%m/%d %H:%M:%S'),
         ))
Пример #5
0
 def get_date(self, __soap):
     try:
         news_date = __soap.select_one(self.date).text.replace(
             u'ي', u'ی').strip()
         news_date.encode('utf-8')
         news_date = self.get_date_str(news_date)
         return khayyam.JalaliDatetime().strptime(
             news_date, u'{}'.format(self.date_format)).todatetime()
     except:
         Debug.get_exception(sub_system='engine_feed',
                             severity='error',
                             tags='get_date_news',
                             data=self.error_link)
         return datetime.datetime.now()
Пример #6
0
    def get_bolton(bolton_types, _b):
        def find_type(_id):
            for j in bolton_types:
                if j['_id'] == _id:
                    return dict(_id=str(j['_id']), name=j['name'])
            return dict(_id=None, name="ندارد")

        for i in _b['sections']:
            i['pattern'] = str(i['pattern'])
            i['_id'] = str(i['_id'])
        return dict(_id=str(_b['_id']),
                    name=_b['name'],
                    date=khayyam.JalaliDatetime(
                        _b['date']).strftime("%Y/%m/%d"),
                    type=find_type(_b['type']),
                    format=str(_b['format']),
                    manual=_b['manual'],
                    active=_b['active'] if 'active' in _b.keys() else True,
                    sections=_b['sections'])
Пример #7
0
    def get_statistic(self, q):
        try:
            d = (q['end_time'] - q['start_time']).seconds
            minute = d / 60
            second = d % 60
            different = {
                'minute': str(minute) if minute > 9 else '0' + str(minute),
                'second': str(second) if second > 9 else '0' + str(second)
            }
        except:
            try:
                d = (datetime.datetime.now() - q['start_time']).seconds
                minute = d / 60
                second = d % 60
                different = {
                    'minute': str(minute) if minute > 9 else '0' + str(minute),
                    'second': str(second) if second > 9 else '0' + str(second)
                }
            except:
                different = {'minute': '00', 'second': '00'}

        try:
            end_time = khayyam.JalaliDatetime(q['end_time']).strftime('%Y/%m/%d %H:%M:%S')
        except:
            end_time = None
        self.value.append(
            dict(
                id=q['_id'],
                count_read_news=q['count_read_news'],
                start_time=CustomDateTime().get_time_difference(q['start_time']),
                end_time=end_time,
                different=different,
                error=q['error'],
                message=q['message'],
                killed=q['killed'] if 'killed' in q.keys() else False,
                last_read_links=q['last_read_links'] if 'last_read_links' in q.keys() else None,
                last_read_news=q['last_read_news'] if 'last_read_news' in q.keys() else None,
                count_last_read_news=q['count_last_read_news'] if 'count_last_read_news' in q.keys() else None,
                count_links_read_with_news=q['count_links_read_with_news'],
                count_all_links=q['count_all_links'] if "count_all_links" in q.keys() else 0,
            )
        )
Пример #8
0
 def get_all(self, _page=1, _size=20):
     try:
         __body = {}
         r = MongodbModel(collection='contact_us',
                          body=__body,
                          page=_page,
                          size=_size).get_all_pagination()
         ls = []
         for i in r:
             i['date'] = khayyam.JalaliDatetime(
                 i['date']).strftime('%Y/%m/%d %H:%M:%S')
             ls.append(i)
         self.result['value'] = ls
         self.result['status'] = True
         return self.result
     except:
         Debug.get_exception(sub_system='admin',
                             severity='error',
                             tags='mongodb > get_all',
                             data='collection > elastic_statistic')
         return self.result
Пример #9
0
    def get_time_difference(date):
        now = datetime.datetime.now()
        res = now - date
        if res.days != 0:
            if res.days >= 365:
                return khayyam.JalaliDatetime(date).strftime('%y-%m-%d')
            elif 30 <= res.days < 365:
                return str(res.days / 30) + ' ماه پیش'
            elif res.days < 30:
                return str(res.days) + ' روز پیش'
        else:
            minute, s = divmod(res.seconds, 60)
            hour, minute = divmod(minute, 60)

            if hour > 0 and minute > 0:
                return str(hour) + ' ساعت و ' + str(minute) + ' دقیقه پیش'
            elif hour > 0 and minute == 0:
                return str(hour) + ' ساعت پیش'
            elif hour == 0 and 0 < minute:
                return str(minute) + ' دقیقه پیش'
            else:
                return 'چند لحظه پیش'
Пример #10
0
 def get_top_dates(self):
     try:
         key_word_query = KeyWordClass(user_keyword=self.user_keyword).get_query_keyword()
         body = {
             "size": 0,
             "query": {
                 "filtered": {
                     "filter": {
                         "and": {
                             "filters": [
                                 {
                                     "range": {
                                         "date": {"lt": self.end.isoformat(), "gte": self.start.isoformat()}
                                     }
                                 }
                             ] + key_word_query
                         }
                     },
                 }
             },
             "aggregations": {
                 "date": {
                     "date_histogram": {
                         "field": "date",
                         "interval": "1d"
                     }
                 }
             }
         }
         r = ElasticSearchModel(doc_type=self.doc_type, body=body).search()
         result = []
         for b in r['aggregations']['date']['buckets']:
             date = khayyam.JalaliDatetime().fromtimestamp(b['key'] / 1e3).date()
             result.append(dict(key=str(date), doc_count=b['doc_count']))
         result.reverse()
         return result
     except:
         return []
Пример #11
0
 def Rdate(self,irooz):
     self.irooz = irooz
     
     return khayyam.JalaliDatetime(year=self.sallat,month=self.mahlat,day=self.irooz).strftime('%N/%P/%K')
Пример #12
0
 def render(self, prices=None):
     now_name = khayyam.JalaliDatetime().now().strftime("%A %d %B %Y")
     return self.render_string(
         '../ui_modules/template/companies_box/prices_small_box.html',
         prices=prices,
         now_name=now_name)
Пример #13
0
    def get_time_log(self, type_report_time, page):
        ls = []
        if type_report_time == 'hour':
            end = datetime.datetime.now() - datetime.timedelta(
                days=(page - 1)) + datetime.timedelta(hours=1)
            end = datetime.datetime.strptime(
                str(end.date()) + ' ' + str(end.hour) + ':00:00',
                '%Y-%m-%d %H:%M:%S')
            start = self.generate_date_time(date=end,
                                            add=False,
                                            _type='hours',
                                            value=24)
            while start <= end:
                ls.append(start)
                start = self.generate_date_time(date=start,
                                                add=True,
                                                _type='hours',
                                                value=1)

        elif type_report_time == 'day':
            end = datetime.datetime.now() - datetime.timedelta(days=(
                (page - 1) * 10))
            end = datetime.datetime.strptime(
                str(end.date()) + ' 23:00:00',
                '%Y-%m-%d %H:%M:%S') + datetime.timedelta(hours=1)

            start = self.generate_date_time(date=end,
                                            add=False,
                                            _type='days',
                                            value=10)

            while start <= end:
                ls.append(start)
                start = self.generate_date_time(date=start,
                                                add=True,
                                                _type='days',
                                                value=1)

        elif type_report_time == 'week':
            end = datetime.datetime.now()
            num_day = khayyam.JalaliDatetime(end).weekday()
            end = end + datetime.timedelta(days=(
                6 - num_day)) - datetime.timedelta(weeks=((page - 1) * 10))
            end = datetime.datetime.strptime(
                str(end.date()) + ' 23:00:00',
                '%Y-%m-%d %H:%M:%S') + datetime.timedelta(hours=1)

            start = self.generate_date_time(date=end,
                                            add=False,
                                            _type='weeks',
                                            value=10)

            while start <= end:
                ls.append(start)
                start = self.generate_date_time(date=start,
                                                add=True,
                                                _type='weeks',
                                                value=1)

        elif type_report_time == 'month':
            end = datetime.datetime.now()
            y = end.year
            m = (end.month + 1) - ((page - 1) * 10)
            if m > 12:
                m = 1
                y += 1
            end = datetime.datetime.strptime(
                str(y) + '-' + str(m) + '-01 00:00:00', '%Y-%m-%d %H:%M:%S')

            y = end.year
            m = end.month - 10
            if m <= 0:
                m = 12 - abs(m)
                y -= 1

            start = datetime.datetime.strptime(
                str(y) + '-' + str(m) + '-01 00:00:00', '%Y-%m-%d %H:%M:%S')
            while start <= end:
                ls.append(start)
                y = start.year
                m = start.month + 1
                if m > 12:
                    m = 1
                    y += 1
                start = datetime.datetime.strptime(
                    str(y) + '-' + str(m) + '-01 00:00:00',
                    '%Y-%m-%d %H:%M:%S')
        return ls