Esempio n. 1
0
    def init():
        """
        The method to initialize the PreConverter and PostConverter lambda functions.
        """

        if len(DataTypeConverter.pre_converter_map) != 0 and len(
                DataTypeConverter.post_converter_map) != 0:
            return

        DataTypeConverter.add_to_map("String", lambda obj: str(obj),
                                     lambda obj: str(obj))
        DataTypeConverter.add_to_map("Integer", lambda obj: int(obj),
                                     lambda obj: int(obj))
        DataTypeConverter.add_to_map(
            "Long", lambda obj: int(obj)
            if str(obj) != Constants.NULL_VALUE else None,
            lambda obj: int(obj))
        DataTypeConverter.add_to_map("Boolean", lambda obj: bool(obj),
                                     lambda obj: bool(obj))
        DataTypeConverter.add_to_map("Float", lambda obj: float(obj),
                                     lambda obj: float(obj))
        DataTypeConverter.add_to_map("Double", lambda obj: float(obj),
                                     lambda obj: float(obj))
        DataTypeConverter.add_to_map(
            "Date", lambda obj: dateutil.parser.isoparse(obj).date(),
            lambda obj: obj.isoformat())
        DataTypeConverter.add_to_map(
            "DateTime",
            lambda obj: dateutil.parser.isoparse(obj).astimezone(tz.tzlocal()),
            lambda obj: obj.replace(microsecond=0).astimezone(tz.tzlocal()
                                                              ).isoformat())
        DataTypeConverter.add_to_map(
            "Object",
            lambda obj: DataTypeConverter.pre_convert_object_data(obj),
            lambda obj: DataTypeConverter.post_convert_object_data(obj))
Esempio n. 2
0
    def test_val_finished(self):
        test_datasets = [Dataset.objects.get(short_name=globals.C3S),
                         Dataset.objects.get(short_name=globals.ASCAT),
                         Dataset.objects.get(short_name=globals.SMAP),]

        run = ValidationRun()
        run.start_time = datetime.now(tzlocal())
        run.end_time = datetime.now(tzlocal())
        run.user = self.testuser
        run.save()

        for ds in test_datasets:
            data_c = DatasetConfiguration()
            data_c.validation = run
            data_c.dataset = ds
            data_c.version = ds.versions.first()
            data_c.variable = ds.variables.first()
            data_c.save()

        ref_c = DatasetConfiguration()
        ref_c.validation = run
        ref_c.dataset = Dataset.objects.get(short_name='ISMN')
        ref_c.version = DatasetVersion.objects.get(short_name='ISMN_V20180712_MINI')
        ref_c.variable = DataVariable.objects.get(short_name='ISMN_soil_moisture')
        ref_c.save()

        run.reference_configuration = ref_c
        run.scaling_ref = ref_c
        run.save()

        val_mail.send_val_done_notification(run)
        self.check_outbox()
Esempio n. 3
0
 def get_warnings(self, since=None, until=None):
     since = since or self.deployment_created_at
     until = until or datetime.now(tz=tzlocal())
     errors = {}
     for event in self.get(u'events'):
         if u'unable' not in event[u'message']:
             continue
         event[u'createdAt'] = event[u'createdAt'].replace(tzinfo=tzlocal())
         since = since.replace(tzinfo=tzlocal())
         until = until.replace(tzinfo=tzlocal())
         if since < event[u'createdAt'] < until:
             errors[event[u'createdAt']] = event[u'message']
     return errors
Esempio n. 4
0
def _get_secret_response():
    return {
        'ARN':
        'arn:aws:secretsmanager:us-west-2:12345678:secret:dummy-test-QvDJsW',
        'Name':
        'dummy-test',
        'VersionId':
        'a1b87fb5-453e-42bd-a4f5-fdc0834854ef',
        'SecretString':
        '{"PORT":"80","LABEL":"L1"}',
        'VersionStages': ['AWSCURRENT'],
        'CreatedDate':
        datetime.datetime(2020, 9, 2, 15, 20, 37, 944000, tzinfo=tzlocal()),
        'ResponseMetadata': {
            'RequestId': '17f66dd3-8fad-4dad-a43e-e1ec9c99ef06',
            'HTTPStatusCode': 200,
            'HTTPHeaders': {
                'date': 'Thu, 03 Sep 2020 18:01:47 GMT',
                'content-type': 'application/x-amz-json-1.1',
                'content-length': '292',
                'connection': 'keep-alive',
                'x-amzn-requestid': '17f66dd3-8fad-4dad-a43e-e1ec9c99ef06'
            },
            'RetryAttempts': 0
        }
    }
Esempio n. 5
0
    def test_abortrunningvalidations(self):
        # make sure we don't have real running validations
        running_validations = ValidationRun.objects.filter(
            progress__range=(0, 99))
        assert not running_validations

        # make sure we have a fake running validation for testing
        run = ValidationRun()
        run.start_time = datetime.now(tzlocal())
        run.progress = 50
        run.save()
        run_id = run.id
        running_validations = ValidationRun.objects.filter(
            progress__range=(0, 99))
        assert running_validations

        # run the command
        args = []
        opts = {}
        call_command('abortrunningvalidations', *args, **opts)

        # make sure that our test validation was marked as failed
        running_validations = ValidationRun.objects.filter(
            progress__range=(0, 99))
        assert not running_validations
        test_val = ValidationRun.objects.get(id=run_id)
        assert test_val
        assert test_val.end_time
        assert test_val.progress == -1
Esempio n. 6
0
def create_appointment(cookies=None):
    return requests.post('http://localhost:8080/rest/appointment/create',
                         cookies=cookies,
                         json={
                             'comment':
                             "test",
                             'latitude':
                             50.0,
                             'longitude':
                             50.0,
                             'till': (datetime.now(tzlocal()) +
                                      timedelta(0, 10)).isoformat(),
                             'options': [{
                                 'id':
                                 None,
                                 'comment':
                                 '1',
                                 'dateTime':
                                 '2017-07-03T20:32:56.525+04:00'
                             }, {
                                 'id':
                                 None,
                                 'comment':
                                 '2',
                                 'dateTime':
                                 '2017-07-03T20:32:56.525+04:00'
                             }]
                         })
Esempio n. 7
0
def register_device():
    current_app.logger.debug("Authenticating...")
    remote_ip = request.environ.get("HTTP_X_REAL_IP", request.remote_addr)
    current_app.logger.debug(
        "Input from '%s' on '%s': '%s'", remote_ip, request.environ.get("HTTP_ORIGIN", ""), request.json
    )

    if request.json["registration_code"]:
        user = (
            db.session.query(User)
            .filter_by(registration_code=hash_code(request.json["registration_code"].upper()))
            .first()
        )

        if user:
            if user.registration_expiry and dt.now(tzlocal()) > user.registration_expiry:
                return make_response(
                    jsonify({"error": "Failed to register device", "reason": "Expired registration code"}), 400
                )

            user.registration_code = None
            db.session.commit()
            token = {"ip": remote_ip, "origin": request.environ["HTTP_ORIGIN"], "user_id": user.id}
            return jsonify({"device_token": jwt.encode(token, os.environ.get("SECRET"), algorithm="HS256")})
        else:
            return make_response(jsonify({"error": "Failed to register device", "reason": "User not found"}), 400)

    return make_response(jsonify({"error": "Failed to register device", "reason": "Missing registration code"}), 400)
Esempio n. 8
0
    def __get_local_datetime(self, datetime_string):
        from_zone = tz.tzutc()
        to_zone = tz.tzlocal()

        date = dateutil.parser.parse(datetime_string)
        date.replace(tzinfo=from_zone)

        return date.astimezone(to_zone)
Esempio n. 9
0
def meeting(request, pk):
    selected_meeting = get_object_or_404(Meeting, id=pk)

    # Format the time frame
    if selected_meeting.start:
        begin = selected_meeting.start.astimezone(tz.tzlocal()).strftime(settings.DATETIME_FORMAT)
    else:
        begin = None
    if selected_meeting.end:
        end = selected_meeting.end.astimezone(tz.tzlocal()).strftime(settings.DATETIME_FORMAT)
    else:
        end = None

    if not selected_meeting.end:
        time = begin
    elif selected_meeting.start.date() == selected_meeting.end.date():
        # We don't need to repeat the date
        time = "{} - {}".format(begin, selected_meeting.end.astimezone(tz.tzlocal()).strftime(settings.TIME_FORMAT))
    else:
        time = "{} - {}".format(begin, end)

    if selected_meeting.location and selected_meeting.location.geometry:
        location_geom = selected_meeting.location.geometry
    else:
        location_geom = None

    # Try to find a previous or following meetings using the organization
    # Excludes meetings with more than one organization
    context = {
        "meeting": selected_meeting,
        "time": time,
        'map': build_map_object(),
        "location_json": json.dumps(location_geom),
    }
    if selected_meeting.organizations.count() == 1:
        organization = selected_meeting.organizations.first()
        query = Meeting.objects \
            .annotate(count=Count("organizations")) \
            .filter(count=1) \
            .filter(organizations=organization) \
            .order_by("start")

        context["previous"] = query.filter(start__lt=selected_meeting.start).last()
        context["following"] = query.filter(start__gt=selected_meeting.start).first()

    return render(request, 'mainapp/meeting.html', context)
Esempio n. 10
0
def utc_to_localtime(dt, session=None):
    lang = 'pl'
    if session and 'lang' in session:
        lang = session['lang']

    locale.setlocale(locale.LC_TIME, loc_map[lang])

    d = dt.replace(tzinfo=tz.tzutc()).astimezone(tz.tzlocal())
    return d.strftime('%a, %d %B %Y %H:%M:%S %Z')
Esempio n. 11
0
def isoStr2utc8Str(isoStr):
    # 取出timestamp,解析转成iso8601 navie datetime
    from datetime import datetime
    utc = datetime.strptime(isoStr, '%Y-%m-%dT%H:%M:%S.%fZ')
    # utc navie datetime设置时区,再换成本地时区,最后解析成字符串。时区可以硬编码。
    from dateutil.tz import tz
    utc8Time = utc.replace(tzinfo=tz.tzutc()).astimezone(
        tz.tzlocal()).strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
    # utc8Time = utc.replace(tzinfo=tz.tzutc()).astimezone(tz.tzlocal()).replace(tzinfo=None)
    return utc8Time
Esempio n. 12
0
def is_instantiable(task, date=None):
    instantiation_date = datetime.date.today() if date is None else date
    if task['date_string'] is None or 'every' not in task['date_string'].lower(
    ):
        return False
    task_date = dateutil.parser.parse(task['due_date_utc'])
    logging.debug(f"task_date = {task_date!r}")
    task_local_date = task_date.astimezone(tz.tzlocal()).date()
    logging.debug(f"task_local_date = {task_local_date!r}")
    return task_local_date == instantiation_date
Esempio n. 13
0
def test_interval_should_be_creatable_from_local_datetime():
    test_start = datetime.now(tz=tz.tzlocal()).replace(microsecond=0)
    test_end = test_start + timedelta(hours=1)

    interval = TimeWarriorInterval(1, test_start, test_end, [], None)

    assert interval.get_start() == test_start \
           and interval.get_end() == test_end \
           and interval.get_start_date() == test_start.date() \
           and interval.get_end_date() == test_end.date()
Esempio n. 14
0
 async def convert_utc_to_local(self, utc_time):
     """
     Given a datetime string formatted as "YYYY-MM-DD HH:MM:SS" in zulu time,
     convert to the local timezone equivalent
     :param utc_time:
     :return: The string formatted the same way but in local time
     """
     local_time = datetime.strptime(utc_time, '%Y-%m-%d %H:%M:%S')
     local_time = local_time.replace(tzinfo=tz.tzutc())
     local_time = local_time.astimezone(tz.tzlocal())
     return local_time
Esempio n. 15
0
    def test_val_expired(self):
        run = ValidationRun()
        now = datetime.now(tzlocal())
        run.start_time = now - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS -
            settings.VALIDATION_EXPIRY_WARNING_DAYS)
        run.end_time = run.start_time + timedelta(days=1)
        run.user = self.testuser
        run.save()
        assert not run.expiry_notified

        val_mail.send_val_expiry_notification([run])
        self.check_outbox()

        assert ValidationRun.objects.get(pk=run.id).expiry_notified

        # multiple validations in one email:
        run = ValidationRun()
        now = datetime.now(tzlocal())
        run.start_time = now - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS -
            settings.VALIDATION_EXPIRY_WARNING_DAYS)
        run.end_time = run.start_time + timedelta(days=1)
        run.user = self.testuser
        run.save()
        assert not run.expiry_notified

        run_2 = ValidationRun()
        now = datetime.now(tzlocal())
        run_2.start_time = now - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS -
            settings.VALIDATION_EXPIRY_WARNING_DAYS)
        run_2.end_time = run_2.start_time + timedelta(days=1)
        run_2.user = self.testuser
        run_2.save()
        assert not run_2.expiry_notified

        val_mail.send_val_expiry_notification([run, run_2])

        assert ValidationRun.objects.get(pk=run.id).expiry_notified
        assert ValidationRun.objects.get(pk=run_2.id).expiry_notified
Esempio n. 16
0
    def adjust_ib_time_to_local(self, timestamp_ib):

        if getattr(timestamp_ib, "tz_localize", None) is None:
            # daily, nothing to do
            return timestamp_ib

        timestamp_ib_with_tz = self.add_tz_to_ib_time(timestamp_ib)
        local_timestamp_ib_with_tz = timestamp_ib_with_tz.astimezone(
            tz.tzlocal())
        local_timestamp_ib = strip_tz_info(local_timestamp_ib_with_tz)

        return local_timestamp_ib
Esempio n. 17
0
    def _adjust_ib_time_to_local(self, timestamp_ib) -> datetime.datetime:

        if getattr(timestamp_ib, "tz_localize", None) is None:
            # daily, nothing to do
            return timestamp_ib

        # IB timestamp already includes tz
        timestamp_ib_with_tz = timestamp_ib
        local_timestamp_ib_with_tz = timestamp_ib_with_tz.astimezone(tz.tzlocal())
        local_timestamp_ib = strip_timezone_fromdatetime(local_timestamp_ib_with_tz)

        return local_timestamp_ib
Esempio n. 18
0
    def __get_local_datetime(datetime_input):
        if type(datetime_input) is str:
            local_datetime = dateutil.parser.parse(datetime_input)
        elif type(datetime_input) is datetime:
            if datetime_input.tzinfo is None:
                local_datetime = datetime_input.replace(tzinfo=tz.tzutc())
            else:
                local_datetime = datetime_input

        else:
            raise TypeError("Unknown type for datetime input: {}".format(
                type(datetime_input)))

        return local_datetime.astimezone(tz.tzlocal())
Esempio n. 19
0
 def f(now):
     tmp = []
     num = 0
     for ii in gen_dst_ips(start=13, end=129):
         jj = ATTACK_TYPE[num % 7]
         num += 1
         tmp.append([
             '202.10.16.11', smg, 1, ii, jj, now,
             arrow.get(now, format, tzinfo=tz.tzlocal()).shift(
                 minutes=1).format('YYYY-MM-DD HH:mm:ss'), 276112380,
             269640, 276112380, 26964, 9203746, 8988, 9203746, 8988, '中国',
             '河南', '信阳', '223'
         ])
     return tmp
Esempio n. 20
0
 def send_alerts(self, observable, fail=True):
     communication = ObservableCommunication(observable, fail)
     for alert in self:
         seconds = observable.get_line_value('seconds', 0)
         since = self.sma.results.get_observable_result(observable).get('since')
         since = (dateutil.parser.parse(since) if since else datetime.datetime.now()).replace(tzinfo=tzlocal())
         dt = datetime.datetime.now().replace(tzinfo=tzlocal())
         if alert.section in self.sma.results.get_observable_result(observable)['alerted']:
             continue
         elif seconds and dt - since <= datetime.timedelta(seconds=seconds):
             continue
         success = alert.send(communication['subject'], communication['message'], **communication.alert_kwargs())
         if success:
             self.sma.results.add_alert_to_observable_result(observable, alert.section)
def extract_single_fill(single_fill):
    is_bag_fill = single_fill.contract.secType == "BAG"
    if is_bag_fill:
        return None
    commission = single_fill.commissionReport.commission
    commission_ccy = single_fill.commissionReport.currency
    cum_qty = single_fill.execution.cumQty
    sign = sign_from_BOT_SEL(single_fill.execution.side)
    signed_qty = cum_qty * sign
    price = single_fill.execution.price
    avg_price = single_fill.execution.avgPrice

    # move to local time and strip TZ info
    time = single_fill.execution.time.astimezone(tz.tzlocal())
    time = datetime.datetime.fromtimestamp(time.timestamp())
    temp_id = single_fill.execution.orderId
    client_id = single_fill.execution.clientId
    contract_month = single_fill.contract.lastTradeDateOrContractMonth

    singleFill = namedtuple(
        "singleFill",
        [
            "commission",
            "commission_ccy",
            "cum_qty",
            "price",
            "avg_price",
            "time",
            "temp_id",
            "client_id",
            "signed_qty",
            "contract_id",
        ],
    )

    single_fill = singleFill(
        commission,
        commission_ccy,
        cum_qty,
        price,
        avg_price,
        time,
        temp_id,
        client_id,
        signed_qty,
        contract_month,
    )

    return single_fill
Esempio n. 22
0
def test_interval_should_be_creatable_from_utc_string():
    test_start = datetime.now(tz=tz.tzlocal()).replace(microsecond=0)
    test_start_utc = test_start.utcnow()
    test_end = test_start + timedelta(hours=1)
    test_end_utc = test_start_utc + timedelta(hours=1)

    interval = TimeWarriorInterval(1,
                                   "{:%Y%m%dT%H%M%S}Z".format(test_start_utc),
                                   "{:%Y%m%dT%H%M%S}Z".format(test_end_utc),
                                   [], None)

    assert interval.get_start() == test_start \
           and interval.get_end() == test_end \
           and interval.get_start_date() == test_start.date() \
           and interval.get_end_date() == test_end.date()
Esempio n. 23
0
def generate_output_directory_string(working_path: str) -> str:
    """ Generates output folder string in format ``YYMMDD_HHMMSS_ABC``
    that will be appended at the end of working dir.

    The handling of the timestamp can be checked in
    https://docs.python.org/3.6/library/datetime.html#strftime-strptime-behavior.

    Args:
        working_path (str): Working path of the project where the results will be saved.

    Returns:
        str: unique folder in the working path were results will be saved.

    """
    # Generate output folders with timestamp
    timestamp = datetime.now(tz.tzlocal()).strftime('%y%m%d_%H%M%S')
    job_id = ''.join(
        random.choices(string.ascii_uppercase + string.digits, k=3))

    return f'{working_path}/{timestamp}_{job_id}'
Esempio n. 24
0
def map_distinct_attributes_to_results(distinct_attributes, query_result):
    """
    Maps the attribute names from a distinct filter onto the results given by the result
    of a query

    When selecting multiple (but not all) attributes in a database query, the results
    are returned in a list and not mapped to an entity object. This means the 'normal'
    functions used to process data ready for output (`entity_to_dict()` for the ICAT
    backend) cannot be used, as the structure of the query result is different.

    :param distinct_attributes: List of distinct attributes from the distinct
        filter of the incoming request
    :type distinct_attributes: :class:`list`
    :param query_result: Results fetched from a database query (backend independent due
        to the data structure of this parameter)
    :type query_result: :class:`tuple` or :class:`list` when a single attribute is
        given from ICAT backend, or :class:`sqlalchemy.engine.row.Row` when used on the
        DB backend
    :return: Dictionary of attribute names paired with the results, ready to be
        returned to the user
    """
    result_dict = {}
    for attr_name, data in zip(distinct_attributes, query_result):
        # Splitting attribute names in case it's from a related entity
        split_attr_name = attr_name.split(".")

        if isinstance(data, datetime):
            # Workaround for when this function is used on DB backend, where usually
            # `_make_serializable()` would fix tzinfo
            if data.tzinfo is None:
                data = data.replace(tzinfo=tzlocal())
            data = DateHandler.datetime_object_to_str(data)

        # Attribute name is from the 'origin' entity (i.e. not a related entity)
        if len(split_attr_name) == 1:
            result_dict[attr_name] = data
        # Attribute name is a related entity, dictionary needs to be nested
        else:
            result_dict.update(map_nested_attrs({}, split_attr_name, data))

    return result_dict
Esempio n. 25
0
def filtro(buffer, arrayContactos, pathArmazenanto, user):
    filtros = {
        "messageStorageState": 0,
        "parentMessageId": 0,
        "composetime": 0
    }
    global idM
    sender = ""
    time = ""
    arrayReacoes = []
    indexTexto = 0
    indexTextoFinal = 0
    name = ""
    isRichHtml = False
    isRichHtmlDone = False
    richHtml = ""
    reacaoChunk = ""
    isReacaoChunk = False
    hasFiles = False
    cvId = ""
    message = ""
    elogio = ""
    adptiveCard = False
    reacaoChunkReady = False
    files = []
    ok = 1
    link = ""
    hrefLink = ""

    for filter in filtros:
        for line in buffer:
            if filter in line:
                filtros[filter] = 1
    for y, x in filtros.items():
        if x == 0:
            ok = 0
    if ok:
        mention = ""
        for line in buffer:
            name = ""
            if "conversationId\"[" in line or "@thread.tacv2" in line:
                indexCvId = line.find("conversationId\"")
                indexCvIdFinal = line.find(".spaces", indexCvId)
                if indexCvIdFinal == -1:
                    indexCvIdFinal = line.find("d.tacv2", indexCvId)
                l = list(line)
                for x in range(indexCvId + 16, indexCvIdFinal + 7):
                    cvId += l[x]
            if "imdisplayname" in line:
                indexTexto = line.find("imdisplayname")
                indexTextoFinal = line.find("\"", indexTexto + 16)
                l = list(line)
                for x in range(indexTexto + 15, indexTextoFinal):
                    name += l[x]
                sender = name
            name = ""

            if "creator" in line:
                indexOrgid = line.find("creator\",8:orgid:")
                indexOrgid += 17
                indexOrgidFinal = line.find("\"", indexOrgid)
                l = list(line)
                org = ""
                for x in range(indexOrgid, indexOrgidFinal):
                    org += l[x]
                orgid = org

            if "composetime" in line:
                indexTempo = line.find("originalarrivaltime")
                indexTempoFinal = line.find("clientArrivalTime", indexTempo)

                l = list(line)
                for x in range(indexTempo + 21, indexTempoFinal - 2):
                    name = name + l[x]
                name = name.replace("\"", "")

                try:
                    dtStart = zulu.parse(name)
                    time = datetime.utcfromtimestamp(dtStart.timestamp())
                    time = time.astimezone(tz=tz.tzlocal())
                    time = name
                except:
                    time = "sem tempo"

                nAspas = False

            if "RichText/Html" in line:
                isRichHtml = True
                richHtml += line

            if "renderContent" in line:
                isRichHtml = False
                isRichHtmlDone = True

            if isRichHtml:
                richHtml += line

            if isRichHtmlDone:
                if "<div>".encode("utf-16le") in line.encode("utf-8"):
                    st = MSTeamsDecoder.utf16customdecoder(richHtml, "<div>")
                    richHtml = st
                    if "https://statics.teams.cdn.office.net/evergreen-assets/skype/v2/" in st:
                        indexMultiplosEmojis = 0
                        indexSpan = 0
                        while indexSpan != -1:
                            indexSpan = st.find("<span class=\"animated-emoticon", indexMultiplosEmojis)
                            indexMultiplosEmojis = indexSpan
                            indexSpanfinal = st.find("</span>", indexSpan)
                            indexSpanfinal += 7
                            l = list(st)

                            span = ""
                            emoji = ""
                            for x in range(indexSpan, indexSpanfinal):
                                span = span + l[x]

                            indexEmoji = span.find("itemid=\"")
                            indexEmojiFinal = span.find(" itemscope")
                            indexEmoji += 7
                            spanList = list(span)
                            for x in range(indexEmoji + 1, indexEmojiFinal - 1):
                                emoji += spanList[x]
                            st = st.replace(span, " " + linkEmoji.format(emoji) + " ")
                            st = st.replace(r"\n", "")
                            richHtml = st
                if "https://statics.teams.cdn.office.net/evergreen-assets/emojioneassets/" in richHtml:
                    indexEmojione = richHtml.find("<img")
                    indexEmojioneFinal = richHtml.find("/>", indexEmojione)
                    l = list(richHtml)

                    emojiReplace = ""
                    for x in range(indexEmojione, indexEmojioneFinal + 2):
                        emojiReplace += l[x]
                    indexLinkEmoji = emojiReplace.find("src")
                    indexLinkEmojiFinal = emojiReplace.find("width", indexLinkEmoji)
                    emojiOne = ""
                    le = list(emojiReplace)
                    for x in range(indexLinkEmoji + 5, indexLinkEmojiFinal - 3):
                        emojiOne += le[x]
                    richHtml = richHtml.replace(emojiReplace, emojiOne)
                    richHtml = richHtml[richHtml.find(r"\n"):richHtml.__len__()]
                if "http://schema.skype.com/Mention" in richHtml:
                    indexMencionado = 0
                    span = ""
                    while indexMencionado != -1:

                        indexMencionado = richHtml.find("<span itemscope itemtype=\"http://schema.skype.com/Mention\"",
                                                        indexMencionado)
                        indexMencionadoFinal = richHtml.find("</span>", indexMencionado)
                        l = list(richHtml)

                        for x in range(indexMencionado, indexMencionadoFinal):
                            span += l[x]
                        indexSpanMention = span.find("itemid") + 11
                        s = list(span)
                        for x in range(indexSpanMention, len(s)):
                            name += s[x]
                        richHtml = richHtml.replace(span + "</span>", "Mention: {0}".format(name))
                        span = ""
                        mention = name
                        name = ""
                if "http://schema.skype.com/AMSImage" in richHtml:
                    l = list(richHtml)

                    src = " "
                    img = ""
                    indexSrc = richHtml.find("src=\"")
                    indexSrcFinal = richHtml.find("\" width")
                    indexImg = richHtml.find("<img")
                    indexImgFinal = richHtml.find("/>", indexImg)
                    for x in range(indexSrc + 5, indexSrcFinal):
                        src += l[x]
                    for x in range(indexImg, indexImgFinal + 2):
                        img += l[x]
                    src += " "
                    indexRH = richHtml.find(r"RichText/Html")
                    replaceRH = ""
                    for x in range(0, indexRH):
                        replaceRH += l[x]
                    richHtml = richHtml.replace(replaceRH, "", 1)
                    richHtml = richHtml.replace(img, src)
                    richHtml = richHtml.replace(r"RichText/Html", "")
                    richHtml = richHtml.replace(r"contenttype", "")
                    richHtml = richHtml.replace(r"contentc", "")
                    richHtml = richHtml.replace(r"text", "")
                    richHtml = richHtml.replace("<span>", "")
                    richHtml = richHtml.replace("<div>", "")
                    richHtml = richHtml.replace("</span>", "")
                    richHtml = richHtml.replace("</div>", "")
                    richHtml = richHtml.replace(r"\n", "")
                    richHtml = richHtml.replace("\"", "")
                    richHtml = richHtml[3::]

                    richHtml = "RichText<div>" + richHtml
                    richHtml += "</div>"

                if "http://schema.skype.com/InputExtension\"><span itemprop=\"cardId\"" in richHtml:
                    indexAdaptiveCard = richHtml.find("<span itemid")
                    indexAdaptiveCardFinal = richHtml.find("</div></div></div></div></div></div></div>",
                                                           indexAdaptiveCard)
                    spanCard = ""
                    l = list(richHtml)
                    for x in range(indexAdaptiveCard, indexAdaptiveCardFinal + 35):
                        spanCard += l[x]
                    richHtml = richHtml.replace(spanCard, "A praise was given to ")
                    adptiveCard = True
                    richHtml = richHtml.replace("<div>", "")
                    richHtml = richHtml.replace("</div>", "")
                    richHtml = "RichText<div>" + richHtml
                    richHtml += "</div>"

                if richHtml.find("RichText") != -1:
                    rHtml = ""
                    richHtml = richHtml.replace("<div style=\"font-size:14px;\"", "")
                    l = list(richHtml)
                    indexTexto = richHtml.find("<div")
                    for x in range(richHtml.find(r"RichText"), indexTexto):
                        rHtml += l[x]
                    indexTexto += 5
                    indexTextoFinal = richHtml.find("</div>")
                    indexHref = 0
                    for x in range(indexTexto, indexTextoFinal):
                        name = name + l[x]
                    name = name.replace("<div>", "")
                    name = name.replace(rHtml, "")
                    name = name.replace("\n", "")
                    name = name.strip()
                    # if name.find(r"\n",0,3)!=-1:
                    #     name = name.replace(r"r\")
                    if name.find("<a href") != -1:
                        n = list(name)
                        while True:
                            br = False
                            if "externalid" in name:
                                break
                            indexHref = name.find("<a href", indexHref)
                            if indexHref == -1:
                                break
                            indexHrefFinal = name.find("</a>", indexHref) + 4
                            indexTitle = name.find(" title=", indexHref)

                            for x in range(indexHref, indexHrefFinal):
                                try:
                                    hrefLink += n[x]
                                except:
                                    br = True
                                    break
                            if br:
                                break
                            if name.find("\" rel", indexHref, indexTitle) != -1:
                                indexTitle = name.find("\" rel", indexHref, indexTitle)
                            for x in range(indexHref + 9, indexTitle):
                                link += n[x]
                            name = name.replace(hrefLink, link)
                            indexHref += 20
                            hrefLink = ""
                            link = ""
                    if name.find("<div itemprop=\"copy-paste-block\"") != -1:
                        name = name.replace("<div itemprop=\"copy-paste-block\"", "")
                    nAspas = False
                    name = name.replace(r"&quot;", "\"")
                    name = name.replace("<u>", "")
                    if name.find(">", 2):
                        name = name.replace(">", "", 1)
                    message = name
                    message = message.replace("Mention:  ", "")
                    name = ""
                    isRichHtmlDone = False
            if "http://schema.skype.com/File" in line:
                indexFileUrl = 0
                indexNomeFile = 0
                while True:
                    localizacao = ""
                    indexFileUrl = line.find("fileUrl", indexFileUrl)
                    if indexFileUrl == -1:
                        break
                    indexFileUrl += 10
                    indexFileUrlFinal = line.find("siteUrl", indexFileUrl) - 3
                    if line.find("itemId", indexFileUrl) < indexFileUrlFinal and line.find("itemId",
                                                                                           indexFileUrl) != -1:
                        indexFileUrlFinal = line.find("itemId", indexFileUrl) - 3
                    indexNomeFile = line.find("fileName", indexNomeFile) + 11
                    indexNomeFileFinal = line.find("fileType", indexNomeFile) - 3
                    if line.find("filePreview", indexNomeFile) < indexNomeFileFinal and line.find("filePreview",
                                                                                                  indexNomeFile) != -1:
                        indexNomeFileFinal = line.find("filePreview", indexNomeFile) - 3
                    indexCleanTexto = richHtml.find("<div><span><img")
                    indexCleanTextoFinal = richHtml.find("</div>", indexCleanTexto) + 6
                    if indexCleanTexto != -1 and indexCleanTextoFinal != -1 and indexCleanTexto < indexCleanTextoFinal:
                        r = list(richHtml)
                        spanDelete = ""
                        for x in range(indexCleanTexto, indexCleanTextoFinal):
                            spanDelete += r[x]
                        richHtml = richHtml.replace(spanDelete, "")
                    l = list(line)

                    url = ""
                    nomeFile = ""
                    for x in range(indexFileUrl, indexFileUrlFinal):
                        url += l[x]
                    for x in range(indexNomeFile, indexNomeFileFinal):
                        nomeFile += l[x]

                    indexFileUrl += 50
                    indexNomeFile += 20
                    fich = File(url, nomeFile)
                    files.append(fich)
                    if files.__len__() != 0:
                        hasFiles = True
            if adptiveCard and "\"type\":\"AdaptiveCard\"" in line:
                indexAltText = line.find("altText")
                indexAltTextFinal = line.find("horizontalAlignment", indexAltText)
                l = list(line)

                for x in range(indexAltText + 10, indexAltTextFinal - 3):
                    elogio += l[x]

            if "call-log" in line:

                start = ""
                end = ""
                state = ""
                originator = ""
                target = ""
                indexStart = line.find("startTime")
                indexStartFinal = line.find("connectTime", indexStart)
                indexEnd = line.find("endTime", indexStartFinal)
                indexEndFinal = line.find("callDirection", indexEnd)
                indexCallState = line.find("callState", indexEndFinal)
                indexOriginator = line.find("originator", indexCallState)
                indexTarget = line.find("target", indexOriginator)
                indexTargetFinal = line.find("originatorParticipant", indexTarget)
                l = list(line)

                for x in range(indexStart + 12, indexStartFinal - 3):
                    start += l[x]
                for x in range(indexEnd + 10, indexEndFinal - 3):
                    end += l[x]
                for x in range(indexCallState + 12, indexOriginator - 3):
                    state += l[x]
                for x in range(indexOriginator + 21, indexTarget - 3):
                    originator += l[x]
                for x in range(indexTarget + 17, indexTargetFinal - 3):
                    target += l[x]
                if originator in arrayContactos:
                    contactoOriginator = arrayContactos.get(originator)
                else:
                    ind = line.find("originatorParticipant")
                    contactoOriginator = Contacts.Contacto("Desc.", "sem email", originator)
                    arrayContactos[originator] = contactoOriginator
                if target in arrayContactos:
                    contactoTarget = arrayContactos.get(target)
                else:
                    displayTarget = ""
                    contactoTarget = Contacts.Contacto("desc.", "sem email", target)
                    arrayContactos[target] = contactoTarget
                dtStart = zulu.parse(start)
                callstart = datetime.utcfromtimestamp(dtStart.timestamp())
                callstart = callstart.astimezone(tz=tz.tzlocal())
                dtEnd = zulu.parse(end)
                callEnd = datetime.utcfromtimestamp(dtEnd.timestamp())
                callEnd = callEnd.astimezone(tz=tz.tzlocal())
                chamada = Chamada(contactoOriginator, str(callstart), str(callEnd), contactoTarget, state)
                arrayCallOneToOne.append(chamada)
            if isReacaoChunk and "ams_references" in line:
                isReacaoChunk = False
                reacaoChunkReady = True

            if isReacaoChunk:
                reacaoChunk += line
                reacaoChunk += ";"
            if "deltaEmotions" in line:
                isReacaoChunk = True

            if reacaoChunkReady:
                emojiReaction = ""
                timeReaction = ""
                arrayReacoes.clear()
                reacoes = reacaoChunk.split(";")
                reacoes = list(dict.fromkeys(reacoes))
                orgidReact = ""
                for r in reacoes:
                    if r != "":
                        reaction = Reaction()
                        rl = list(r)
                        indexKey = r.find("key")
                        indexKeyFinal = r.find("user", indexKey)
                        if indexKey != -1:
                            emojiReaction = ""
                            for x in range(indexKey + 5, indexKeyFinal - 2):
                                emojiReaction += rl[x]
                        indexOrgidReacao = r.find("orgid")
                        indexOrgidReacaoFinal = r.find("timeN", indexOrgidReacao)
                        for x in range(indexOrgidReacao + 6, indexOrgidReacaoFinal - 2):
                            orgidReact += rl[x]
                        try:
                            for x in range(0, 13):
                                timeReaction += rl[x]
                        except:
                            print("")
                        reaction.orgid = orgidReact
                        reaction.emoji = linkEmoji.format(emojiReaction)
                        try:
                            tr = datetime.utcfromtimestamp(float(timeReaction) / 1000.0)
                            tr = tr.astimezone(tz=tz.tzlocal())
                            reaction.time = str(tr)
                        except Exception:
                            reaction.time = str(timeReaction)
                        if reaction.time.find("value")==-1:
                            arrayReacoes.append(reaction)
                        orgidReact = ""
                        timeReaction = ""
                        reacaoChunkReady = False

        reacaoChunk = ""
        if message != "" or hasFiles:
            if message.count("A praise was given to") < 2:
                if "Call Log for Call" not in message:
                    if adptiveCard:
                        message += "Praise: {}".format(elogio)
                        message = message.replace(r"\n'", "")
                        message = message.replace("\"", "")
                        elogio = ""
                        adptiveCard = False
                    mensagem = MensagemCompleta()
                    mensagem.mention = mention
                    mensagem.message = cleanMessage(message)
                    mensagem.time = time
                    mensagem.sender = sender
                    mensagem.cvID = cvId
                    if arrayReacoes.__len__() > 0:
                        with open(os.path.join(pathArmazenanto, 'Reacts_{}_{}.csv'.format(user,tmCSV)), 'a+', newline='',
                                  encoding="utf-8") as csvfile:
                            messagewriter = csv.writer(csvfile, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)
                            for r in arrayReacoes:
                                if r.orgid in arrayContactos:
                                    c = arrayContactos.get(r.orgid)
                                else:
                                    c = Contacts.Contacto(orgid=r.orgid)
                                messagewriter.writerow([str(idM), r.emoji, c.nome, r.time, user])
                            csvfile.close()
                    mensagem.files = files
                    arrayMensagens.append(mensagem)
                    hasFiles = False
                    idM += 1
                    arrayReacoes.clear()
def timestamp_converter(st_time):
    time = datetime.fromtimestamp(st_time,
                                  tz=tz.tzlocal()).strftime('%d/%m/%Y-%H:%M')
    return time
Esempio n. 27
0
    def get_broker_time_local_tz(self) -> datetime.datetime:
        ib_time = self.ib.reqCurrentTime()
        local_ib_time_with_tz = ib_time.astimezone(tz.tzlocal())
        local_ib_time = strip_timezone_fromdatetime(local_ib_time_with_tz)

        return local_ib_time
Esempio n. 28
0
    def get_broker_time_local_tz(self):
        ib_time = self.ib.reqCurrentTime()
        local_ib_time_with_tz = ib_time.astimezone(tz.tzlocal())
        local_ib_time = strip_tz_info(local_ib_time_with_tz)

        return local_ib_time
Esempio n. 29
0
async def convert_utc_to_local(utc_time):
    local_time = datetime.strptime(utc_time, '%Y-%m-%d %H:%M:%S')
    local_time = local_time.replace(tzinfo=tz.tzutc())
    local_time = local_time.astimezone(tz.tzlocal())
    return local_time
def meeting(request, pk):
    selected_meeting = get_object_or_404(Meeting, id=pk)

    start = selected_meeting.start
    if start:
        # FIXME: That ain't nice for localization
        start_date = start.astimezone(tz.tzlocal()).strftime("%d.%m.%Y")
        start_time = formats.time_format(start.astimezone(tz.tzlocal()))
    else:
        start_date = None
        start_time = None

    end = selected_meeting.end
    if end:
        end_date = end.astimezone(tz.tzlocal()).strftime("%d.%m.%Y")
        end_time = formats.time_format(end.astimezone(tz.tzlocal()))
    else:
        end_date = None
        end_time = None

    if start_date and start_date == end_date:
        # Don't repeat the date
        time = "{} {} - {}".format(start_date, start_time, end_time)
    elif end_date:
        time = "{} {} - {} {}".format(start_date, start_time, end_date,
                                      end_time)
    elif start_date:
        time = "{} {}".format(start_date, start_time)
    else:
        time = _("Unknown")

    if selected_meeting.location and selected_meeting.location.geometry:
        location_geom = selected_meeting.location.geometry
    else:
        location_geom = None

    agenda_items = selected_meeting.agendaitem_set.prefetch_related(
        "consultation__paper__main_file").all()

    # The persons can be listed both in the organization and in the meeting,
    # but we're only interested in the ones only in the meeting
    meeting_persons = set(
        Person.objects.filter(
            membership__organization__meeting=selected_meeting).all())
    extra_persons = set(selected_meeting.persons.all()) - meeting_persons

    # Try to find a previous or following meetings using the organization
    # Excludes meetings with more than one organization
    context = {
        "meeting": selected_meeting,
        "time": time,
        "map": build_map_object(),
        "location_json": json.dumps(location_geom),
        "agenda_items": agenda_items,
        "extra_persons": extra_persons,
    }
    if selected_meeting.organizations.count() == 1:
        organization = selected_meeting.organizations.first()
        query = (Meeting.objects.annotate(count=Count("organizations")).filter(
            count=1).filter(organizations=organization).order_by("start"))

        context["previous"] = query.filter(start__lt=start).last()
        context["following"] = query.filter(start__gt=start).first()

    if selected_meeting.location:
        for_maps = selected_meeting.location.for_maps()
        context["google_maps_url"] = "http://maps.google.de/maps?" + urlencode(
            {"q": for_maps})
        context[
            "osm_url"] = "https://www.openstreetmap.org/search?" + urlencode(
                {"query": for_maps})

    return render(request, "mainapp/meeting.html", context)
Esempio n. 31
0
    def test_deploy_and_wait_unable_to_place_tasks_till_timeout(
            self, mock_log_err):
        deployment = MagicMock()
        start_time = datetime.now(tz=tzlocal())
        deployment.get_service.side_effect = [
            self.create_ecs_service_with_status({
                'desiredCount':
                5,
                'runningCount':
                0,
                'events': [
                    {
                        'message': 'unable to place tasks due to memory',
                        'createdAt': start_time
                    },
                ],
                'deployments': [{
                    'status': 'PRIMARY',
                    'desiredCount': 5,
                    'runningCount': 0,
                    'createdAt': start_time - timedelta(seconds=5),
                    'updatedAt': start_time - timedelta(seconds=5)
                }]
            }),
            self.create_ecs_service_with_status({
                'desiredCount':
                5,
                'runningCount':
                0,
                'events': [
                    {
                        'message': 'unable to place tasks due to memory',
                        'createdAt': start_time + timedelta(seconds=1)
                    },
                ],
                'deployments': [{
                    'status': 'PRIMARY',
                    'desiredCount': 5,
                    'runningCount': 0,
                    'createdAt': start_time - timedelta(seconds=5),
                    'updatedAt': start_time - timedelta(seconds=4)
                }]
            }),
            self.create_ecs_service_with_status({
                'desiredCount':
                5,
                'runningCount':
                0,
                'events': [
                    {
                        'message': 'unable to place tasks due to memory',
                        'createdAt': start_time + timedelta(seconds=2)
                    },
                ],
                'deployments': [{
                    'status': 'PRIMARY',
                    'desiredCount': 5,
                    'runningCount': 0,
                    'createdAt': start_time - timedelta(seconds=5),
                    'updatedAt': start_time - timedelta(seconds=3)
                }]
            }),
        ]

        new_task_definition = EcsTaskDefinition({'containerDefinitions': []})
        color = "green"
        timeout_seconds = 2

        self.assertFalse(
            deploy_and_wait(deployment, new_task_definition, color,
                            timeout_seconds), "expected deployment to fail")

        deployment.deploy.assert_called_with(new_task_definition)
        mock_log_err.assert_called_with('Deployment timed out!')