Example #1
0
    def __init__(self, timeobj):

        if (isinstance(timeobj,TimeUtils)):
            logging.warning("Time object is already a TimeUtils instance. Null operation.")
            self.datetime = timeobj.datetime
        else:
            self.datetime = None

        if isinstance(timeobj,datetime.datetime):
            self.datetime = zulu.Zulu.fromdatetime(timeobj) 
        elif isinstance(timeobj,tuple):
            dt = datetime.datetime(*timeobj)
            self.datetime = zulu.Zulu.fromdatetime(dt)           
        elif isinstance(timeobj,zulu.zulu.Zulu):
            self.datetime = timeobj
        elif isinstance(timeobj,str):
            try:     #Zulu string
                self.datetime = zulu.parse(timeobj)
            except zulu.parser.ParseError:  # Now try synopt string
                try:
                    dt = datetime.datetime(int(timeobj[0:4]),int(timeobj[4:6]),int(timeobj[6:8]),
                                           int(timeobj[8:10]),int(timeobj[10:12]))
                    self.datetime = zulu.Zulu.fromdatetime(dt)
                except AttributeError:
                    logging.error("Invalid time string format for " + timeobj)
Example #2
0
    def get_attributes(event):
        """
        Return event attributes

        :param event: Event Data

        :return: Event attributes
        """

        try:
            converted_time = zulu.parse(event["timestamp"]).timestamp() * 1000
            attributes = {
                "id": event["id"],
                "sitename": event["sitename"],
                "type": event["type"],
                "hostname": event["hostname"],
                "servicedescription": event["service_description"],
                "statetype": event["state_type"],
                "output": event["output"],
                "longoutput": event["long_output"],
                "eventstate": event["event_state"],
                "timestamp": converted_time,
            }
        except (ValueError, KeyError):
            logging.info(f"Invalid event feature data for event: {event}")
            return None
        else:
            return attributes
Example #3
0
    def update_existing_decommissioned_host(self, host, host_info, host_ref):
        """
        Update decommissioned host

        :param host: Host data
        :param host_info: Host information
        :param host_ref: Host Firestore reference
        """

        host_ref.set({"endtime": host["timestamp"]}, merge=True)
        arcgis_updates = {
            "objectid": host_info["objectId"],
            "endtime": zulu.parse(host["timestamp"]).timestamp() * 1000,
        }

        response = self.arcgis_processor.update_feature(
            host_info["longitude"],
            host_info["latitude"],
            arcgis_updates,
            config.LAYER["hosts"],
        )

        if "success" in response:
            logging.info(f"Successfully updated decommissioned host: {host['id']}")
        else:
            logging.error(
                f"Failed updating decommissioned host: {json.dumps(response)}"
            )
Example #4
0
async def fact_check(ctx, *args):
    API = "https://factchecktools.googleapis.com/v1alpha1/claims:search"
    query = ' '.join(args).lower()
    params = {
        "key": config["GOOGLE_API"],
        "query": query,
        "languageCode": "en-US"
    }
    response = loads(requests.get(API, params=params).text)
    if not response:
        await ctx.send(f"I am unable to check that fact!")
    embeds = []
    for i, claim in enumerate(response['claims']):
        review = claim["claimReview"][0]
        publisher = review["publisher"]
        url = review["url"]
        date = zulu.parse(review["reviewDate"]).datetime
        rating = review["textualRating"]

        embed = discord.Embed(title=f"Source #{i + 1}",
                              color=discord.Color.dark_gold(),
                              timestamp=date)
        embed.add_field(
            name="Fact Checker Info: ",
            value=f"Name: {publisher['name']}\nWebsite: {publisher['site']}",
            inline=False)
        embed.add_field(name="Rating: ", value=rating, inline=False)
        embed.add_field(name="More Info: ", value=url, inline=False)

        embeds.append(embed)
    await ctx.send(f"**{len(embeds)}** sources found!")
    paginator = DiscordUtils.Pagination.AutoEmbedPaginator(
        ctx, timeout=30, remove_reactions=True)
    await paginator.run(embeds)
    def test_availability_accessibility(self):
        """
        Test case for a valid availability query. Reads the
        travel properties from test-data.json, sets the
        travel departureTimeEarliest to next monday at 11:00Z.
        Expects valid response for a transport leaving
        19:00+3, one availability for the passenger adult with
        GUIDE_DOG accessibility feature in the reservation.
        """

        # Trip availaibility inquiry
        travel = self.testdata['travel_data_accessibility']
        product = self.testdata['test_products_current_date_response']
        t = datetime.datetime.now()
        travel["travel"]["departureTimeEarliest"]  = zulu.now().shift(days=(7 - t.weekday())). \
            replace(hour=11, minute=00).isoformat()
        r = lippuclient.availability_request(self.envdata['base_url'],
                                             headers=self.headers,
                                             payload=travel)
        logging.info(
            "test_availability_accessibility, availability response: %s" %
            r.json())
        self.assertEqual(r.status_code, 200)
        self.assertEqual(len(r.json()['availability']), 1)
        self.assertEqual(r.json()['contract'], travel['contract'])
        self.assertEqual(r.json()['travel']['productType'],
                         travel['travel']['productType'])
        self.assertEqual(r.json()['travel']['to']['lat'],
                         travel['travel']['to']['lat'])
        self.assertEqual(r.json()['travel']['to']['lon'],
                         travel['travel']['to']['lon'])
        self.assertEqual(r.json()['travel']['from']['lat'],
                         travel['travel']['from']['lat'])
        self.assertEqual(r.json()['travel']['from']['lon'],
                         travel['travel']['from']['lon'])
        for item in r.json()['availability']:
            self.assertNotEqual(item['applicableForPassengers'], 'None')
            self.assertEqual(item['fare']['currency'], 'EUR')
            self.assertEqual(item['fare']['amount'], 14)
            self.assertEqual(item['fare']['vatPercent'], 10)
            for applicable in item['applicableForPassengers']:
                self.assertEqual(applicable['category'], 'Adult')
                self.assertEqual(
                    applicable['category']
                    in product['products2']['suitablePassengerCategories'],
                    True)
                self.assertEqual(applicable['accessibility'][0]['title'],
                                 'GUIDE_DOG')
                self.assertEqual(
                    applicable['accessibility'][0]['fare']['currency'], 'EUR')
                self.assertEqual(
                    applicable['accessibility'][0]['fare']['amount'], 0)
                self.assertEqual(
                    applicable['accessibility'][0]['fare']['vatPercent'], 0)
        self.assertEqual(r.json()['travel']['departureTime'].startswith(
            zulu.now().shift(days=(7 - t.weekday())). \
                replace(hour=19, minute=00).format('%Y-%m-%dT%H:%M')
        ), True)
        logging.info("Departure time: %s" %
                     zulu.parse(r.json()['travel']['departureTime']))
Example #6
0
    def run(self):
        logging.info(self.threadID + " - thread started, query recieved: %s",str(self.query))
        logging.info(self.threadID + " REST endpoint: " + self.rest)

        sessionID = self.threadID
        #setDiscoveryIndex(sessionID)

        allJSONObjects = kpindex.getJSONObjectsFromElasticSearch(self.rest, self.sourceType,self.threadID,self.query,self.maxNumResults)
        logging.info(self.threadID + " -  data retrieved from Elastic search creating index now")

        textData = kpindex.getAllTextData(allJSONObjects)
        indexes,totalDistinctKeywords = kpindex.getBookBackIndexes(self.threadID,textData,allJSONObjects)
        logging.info(self.threadID +  " - Index creation done")
        documentData,totalDocuments = kpindex.getTitles(allJSONObjects)

        currentDateZulu = zulu.now()
        date = zulu.parse(currentDateZulu).isoformat()#datetime.datetime.now().isoformat()

        conceptData,totalConcepts=kpindex.getConcepts(allJSONObjects)
        metadata = {"totalDocuments":totalDocuments,"dateCreated":date,"totalKeywords":totalDistinctKeywords,"totalConcepts":totalConcepts,"title":self.title, "creator": self.creatorID}
        url = self.rest + self.destinationType +"/"+sessionID
        #insertsuccess = kpindex.insertIntoElasticSearch(indexes,documentData,conceptData,metadata,url)

        completedIndex = {"bookback": indexes,"allDocumentData":documentData,"metadata": metadata,"conceptIndex":conceptData}
        setDiscoveryIndex(sessionID,completedIndex)
        logging.info(self.threadID +  "Index stored, thread completed")
Example #7
0
def load_list(items, resp, youtube, canal):
    for k in items:
        bid = k["id"]
        sid = k["contentDetails"]["boundStreamId"]
        #    key,addr=get_streamid_data(youtube,sid)
        key = "xx"
        addr = "xx"
        title = k["snippet"]["title"]
        desc = k["snippet"]["description"]
        pub = k["snippet"]["publishedAt"]
        try:
            sched = k["snippet"]["scheduledStartTime"]
            sdate = zulu.parse(sched, default_tz='UTC')
            sched = utc2local(sdate.naive)
            #    sdate= parser.parse(sched)
            schedt = sched.strftime("%Y-%m-%d %H:%M")
            print(schedt)
        except:
            schedt = "Error fecha"
        stat = (k["status"]["lifeCycleStatus"])
        print()
        resp.append({
            "broadcast_id": bid,
            "titulo": title,
            "desc": desc,
            "Fecha_pub": pub,
            "Fecha_Sched": schedt,
            "Canal": canal,
            "streamId": sid,
            "key": key,
            "ingestionAddr": addr,
            "status": stat
        })
Example #8
0
    def __init__(self):
        right_now = zulu.now()
        dt = zulu.parse(right_now)

        # string field
        self.person_id = str(uuid.uuid4())
        # timestamp
        self.update_timestamp = right_now
        # string fields
        self.firstname = 'fn ' + str(int(dt.timestamp()*100000%100))
        self.lastname = 'ln ' + str(int(dt.timestamp()*100000%99))
        # int fields
        self.sibling_count = randint(0,4)
        self.child_count = randint(0,4)
        # float fields
        self.height = random() * 100
        self.weight = random() * 100
        # date fields
        self.birthdate = datetime.date.today() - datetime.timedelta(days=randint(10000,20000))
        self.account_creation_date = datetime.date.today() - datetime.timedelta(days=randint(1,1000))
        # array field
        self.given_names = [self.firstname,self.lastname]
        # bool field
        self.is_active = randint(0, 10) % 2 == 0
        # byte field
        self.profile_picture = base64.b64encode(self.person_id.encode('utf-8'))
    def test_availability_set_both_times(self):
        """
        Test case for a valid availability query. Reads the
        travel properties from test-data.json, sets the
        travel departureTimeEarliest two days from now to 14:00Z
        and arrivalTimeLatest two days from now at 21:30.
        As both are set, expects the departureTimeEarliest
        to be used for query.Expects valid response for a transport leaving
        20:00+3.
        """

        # Trip availaibility inquiry
        travel = self.testdata['travel_data']
        product = self.testdata['test_products_current_date_response']
        travel["travel"]["departureTimeEarliest"]  = zulu.now().shift(days=2). \
            replace(hour=14, minute=00).isoformat()
        travel["travel"]["arrivalTimeLatest"]  = zulu.now().shift(days=2). \
            replace(hour=21, minute=30).isoformat()
        r = lippuclient.availability_request(self.envdata['base_url'],
                                             headers=self.headers,
                                             payload=travel)
        logging.info(
            "test_availability_both_arrival_time, availability response: %s" %
            r.json())
        self.assertEqual(r.status_code, 200)
        self.assertEqual(len(r.json()['availability']), 3)
        self.assertEqual(r.json()['contract'], travel['contract'])
        self.assertEqual(r.json()['travel']['productType'],
                         travel['travel']['productType'])
        self.assertEqual(r.json()['travel']['to']['lat'],
                         travel['travel']['to']['lat'])
        self.assertEqual(r.json()['travel']['to']['lon'],
                         travel['travel']['to']['lon'])
        self.assertEqual(r.json()['travel']['from']['lat'],
                         travel['travel']['from']['lat'])
        self.assertEqual(r.json()['travel']['from']['lon'],
                         travel['travel']['from']['lon'])
        for item in r.json()['availability']:
            self.assertNotEqual(item['applicableForPassengers'], 'None')
            for applicable in item['applicableForPassengers']:
                self.assertNotEqual(applicable, 'None')
                self.assertEqual(
                    applicable['category']
                    in product['products1']['suitablePassengerCategories'],
                    True)

        self.assertEqual(r.json()['travel']['departureTime'].startswith(
            zulu.now().shift(days=2). \
                replace(hour=20, minute=00).format('%Y-%m-%dT%H:%M')
        ), True)
        self.assertEqual(r.json()['travel']['arrivalTime'].startswith(
            zulu.now().shift(days=2). \
                replace(hour=23, minute=10).format('%Y-%m-%dT%H:%M')
        ), True)

        logging.info("Arrival time: %s" %
                     zulu.parse(r.json()['travel']['arrivalTime']))
Example #10
0
def exchangeRate(original,convert_to,time):
	time = str(zulu.parse(time)) #put in proper format
	time = time.replace('+00:00','Z')
	url = ('https://rest.coinapi.io/v1/exchangerate/'+str(original)+'/'+str(convert_to)+'?time='+str(time)) #get exchange rate from coinAPI
	headers = {'X-CoinAPI-Key' : sys.argv[5]}
	response = requests.get(url, headers=headers)
	body = response.json()
	# print(body['rate'])
	return body['rate']
    def insert_data_point_influxdb(self,msg,measurement,msg_type):

        if msg_type == 'raw':
            json_body4 = [
            {
                    "measurement": measurement,
                    "tags": {
                        "event_type": msg["e"],
                        "base_currency": msg["s"][:int(len(msg["s"])/2)],
                        "quote_currency": msg["s"][int(len(msg["s"])/2):],
                        "pair": msg["s"],
                        "interval": msg["k"]["i"]
                    },
                    "time": zulu.parse(msg["k"]["t"]/1000.0).isoformat(),#datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),#+'Z',
                    "fields": {
                        "open": float(msg["k"]["o"]),
                        "close":float(msg["k"]["c"]),
                        "high":float(msg["k"]["h"]),
                        "low":float(msg["k"]["l"]),
                        "high-low":float(msg["k"]["h"])-float(msg["k"]["l"]),
                        "close-open":float(msg["k"]["c"])-float(msg["k"]["o"]),
                        "volume":float(msg["k"]["v"]), #Base asset volume
                        "number_of_trades":int(msg["k"]["n"]),
                        "quote_volume":float(msg["k"]["q"]), #Quote asset volume
                        "active_buy_volume":float(msg["k"]["V"]), #Taker buy base asset volume
                        "active_buy_quote_volume":float(msg["k"]["Q"]), #Taker buy quote asset volume
                        "gain":-1000,
                        "lose":-1000,
                        "avg_gain":-1000,
                        "avg_lose":-1000,
                        "RSI":-1000,
                        "MACD":-1000,
                        "KDJ":-1000,
                        "DMI":-1000,
                        "OBV":-1000,
                        "MTM":-1000,
                        "EMA":-1000,
                        "VWAP":-1000,
                        "AVL":-1000,
                        "TRIX":-1000,
                        "StochRSI":-1000,
                        "EMV":-1000,
                        "WR":-1000,
                        "BOLL":-1000,
                        "SAR":-1000,
                        "CCI":-1000,
                        "MA":-1000,
                        "VOL":-1000
                    
                    
                    }
                }
            ]    
        self.InfluxClient.write_points(points=json_body4,retention_policy='coin_policy')
        print("inserting message with time: {0}, message type: {1}, measurement: {2}".format(json_body4[0]["time"],msg_type,measurement))
    def get_previous_point(self,current_time_num):

        count = 1    
      #  current_time_num=previous_msg["k"]["t"]/1000.0
        pre_previous_time = zulu.parse(current_time_num-60).isoformat() #I rest 60 seconds
        
        pre_previous_time_query=self.InfluxClient.query("select * from {2} WHERE time = '{0}' AND pair = '{1}';".format(pre_previous_time,self.symbol,self.measurement_name))
        
        while not len(list(pre_previous_time_query)):
            count = count+1
            pre_previous_time_loopty_loop = zulu.parse(current_time_num-count*60).isoformat()
            pre_previous_time_query=self.InfluxClient.query("select * from {2} WHERE time = '{0}' AND pair = '{1}';".format(pre_previous_time_loopty_loop,self.symbol,self.measurement_name))
            print("testing_time: {0}, count:".format(pre_previous_time_loopty_loop),count)

    
    
        event_type = 'kline'
        interval ='1m'     
        units = 'minute'
        num_of_units = count+2 #Just in case I added 2 units more
        msg_type = 'raw'
        self.insert_offline_tick_data(event_type,interval,units,num_of_units,msg_type)
Example #13
0
    def test_commit_auth(self):
        """
        Test case for successful init_auth and commit_auth

        """
        t = zulu.now()
        account_id = self.testdata['valid_client1']

        headers = lippuclient.generate_headers(account_id=account_id)

        r_init = lippuclient.authentication_init_request(
            self.envdata['base_url'], headers, account_id)
        #r_init = requests.post(self.envdata['auth_url'] + '/init',
        #                         headers=headers, json={'account': account_id})
        logging.info("test_commit_auth, response for init: %s" % r_init.text)
        self.assertEqual(r_init.status_code, 200)
        self.assertNotEqual(r_init.json()['nonce'], None)
        self.assertEqual(r_init.json()['user'], account_id)
        self.assertNotEqual(r_init.json()['expires'], None)
        self.assertEqual(zulu.parse(r_init.json()['expires']) > t, True)

        # Commit authentication and receive authentication token.
        headers['X-Message-Id'] = str(uuid.uuid4())
        r_commit = lippuclient.authentication_commit_request(
            self.envdata['base_url'], headers,
            r_init.json()['nonce'], self.testdata['key_id_client1'],
            self.testdata['key_path_client1'], lippuclient.ALG_RSA_SHA256)
        logging.info("test_commit_auth, response for commit: %s" %
                     r_commit.text)

        self.assertEqual(r_commit.status_code, 200)
        self.assertNotEqual(r_commit.json()['token'], None)
        self.assertNotEqual(r_commit.json()['expires'], None)
        self.assertEqual(r_commit.json()['user'], account_id)
        self.assertEqual(zulu.parse(r_commit.json()['expires']) > t, True)
        self.assertEqual(
            zulu.parse(r_commit.json()['expires']) > zulu.parse(
                r_init.json()['expires']), True)
        pass
Example #14
0
 def status(self,
            fromcall,
            statustext,
            timestamp=False
            ):  #APRS101 Page 80 Status Reports; only basic at this time
     if not timestamp:
         statustext = statustext[:62]
         return fromcall.upper() + '>APRS:>' + statustext
     if timestamp:
         statustext = statustext[:55]
         dt = zulu.parse(zulu.now())
         zt = re.findall("\d{6}", str(dt))
         return fromcall.upper() + '>APRS:>' + zt[0] + 'z' + statustext
Example #15
0
def get_scs(env, location_id):
    with open("contracts_list.txt", "r+") as scs:
        scs.truncate(0)
    url = get_scs_url(env=env, location_id=location_id)
    data = (requests.get(url=url, headers={"X-Token": get_token(env)})).json()
    contracts = []
    for record in data:
        contracts.append(record["service-window-start"])
    for contract in contracts:
        dt = zulu.parse(contract)
        usable_contract = f"{(dt.isoformat())[0:-6]}" + "Z"
        with open("contracts_list.txt", "a+") as contracts_list_file:
            contracts_list_file.write(f"{usable_contract}\n")
def _retrieve_folder_images_urls(folder_str):
    asset_list = []
    text_list_links = []
    images_rest_url = S3_ASSET_FOLDER_PREFIX_FILTERING_URL + folder_str
    images_request = Request(images_rest_url)
    text_rest_url = S3_TEXT_FOLDER_PREFIX_FILTERING_URL + folder_str
    text_request = Request(text_rest_url)

    try:
        text_response = urlopen(text_request)
        text_folder_response = text_response.read()
        text_root = ET.fromstring(text_folder_response)
        skip_folder_flag = False
        for child in text_root:
            if child.tag == CONTENTS_XML_TAG_TARGET:
                if skip_folder_flag:
                    text_list_links.append(child[0].text)
                skip_folder_flag = True

        images_response = urlopen(images_request)
        images_folder_response = images_response.read()
        images_root = ET.fromstring(images_folder_response)
        skip_folder_flag = False  #skip the first entry
        idx = -1  #due to skipping first loop am not using enumerate, this idx is used for looping through the text_list_links list
        for child in images_root:
            if child.tag == CONTENTS_XML_TAG_TARGET:
                if skip_folder_flag:  #do not execute on first loop, second loop is when folder contents start
                    unix_timestamp = long(
                        zulu.parse(child[1].text).timestamp())
                    txt = "No Description"
                    if idx < len(text_list_links):
                        txt = urlopen(S3_TEXT_BASE_URL +
                                      text_list_links[idx]).read()
                    asset = folder_asset.FolderAsset(
                        S3_ASSET_BASE_URL + child[0].text, unix_timestamp, txt)
                    asset_list.append(asset)
                skip_folder_flag = True
                idx += 1
        return sorted(asset_list, key=lambda asset: asset.upload_time)

    except URLError, error:
        print 'Got an error code:', error
Example #17
0
    def test_authenticate(self):
        """
        Test case for successful authentication

        """
        t = zulu.now()
        account_id = self.testdata['valid_client1']

        response = lippuclient.authenticate(self.envdata['base_url'],
                                            str(uuid.uuid4()), account_id,
                                            self.testdata['key_id_client1'],
                                            self.testdata['key_path_client1'],
                                            lippuclient.ALG_RSA_SHA256)
        logging.info("test_authenticate, response is: %s" % response.text)

        self.assertEqual(response.status_code, 200)
        self.assertNotEqual(response.json()['token'], None)
        self.assertNotEqual(response.json()['expires'], None)
        self.assertEqual(response.json()['user'], account_id)
        self.assertEqual(zulu.parse(response.json()['expires']) > t, True)
        pass
Example #18
0
    def get_host_object(self, host):
        """
        Get host object

        :param host: Host data

        :return: Host data
        """
        try:
            bssglobalcoverage, bsshwfamily, bsslifecyclestatus = self.get_bss_variables(
                host
            )
            start_time = zulu.parse(host["timestamp"]).timestamp() * 1000

            host = {
                "id": host["id"],
                "sitename": host["sitename"],
                "hostname": host["hostname"],
                "decommissioned": host["decommissioned"],
                "hostgroups": host["host_groups"],
                "bssglobalcoverage": bssglobalcoverage,
                "bsshwfamily": bsshwfamily,
                "bsslifecyclestatus": bsslifecyclestatus,
                "status": 0,  # OK
                "giskleur": 0,  # GREEN
                "type": "HOST",
                "event_output": "Initial display - NS-TCC-GIS",
                "starttime": start_time,
                "longitude": get_from_dict(host, ["longitude", "value"]),
                "latitude": get_from_dict(host, ["latitude", "value"]),
            }

            if host["longitude"] is None or host["latitude"] is None:
                raise ValueError("Longitude and/or latitude is missing")

        except (TypeError, ValueError, KeyError) as e:
            logging.info(f"Invalid host feature data for host: {host}: {str(e)}")
            return None
        else:
            return host
Example #19
0
 def get_plan_times(self):
     # Returns list of scheduled start times of service times (no rehearsals) in dict form:
     # zulu time and human readable time, as well as plan time id
     logger.debug('get_plan_times. service_type: %s, service_id: %s',
                  self.service_type, self.plan_id)
     r = requests.get(
         f'https://api.planningcenteronline.com/services/v2/service_types/{self.service_type}/plans/{self.plan_id}/plan_times/',
         auth=(APP_ID, SECRET))
     r = json.loads(r.text)
     logger.debug('get_plan_times: response received: %s', r)
     times = []
     for service_time in r['data']:
         if not service_time['attributes']['time_type'] == 'rehearsal':
             z = service_time['attributes']['starts_at']
             local = zulu.parse(z).format('%Y-%m-%d  %H:%M', tz='local')
             times.append({
                 'z': z,
                 'local': local,
                 'id': service_time['id']
             })
     logger.debug('Found plan times: %s', times)
     return times
Example #20
0
def filtro(buffer):
    filtros = {
        "trimmedMessageContent": 0,
        "renderContent": 0,
        "skypeguid": 0
    }
    sender = ""
    time = ""
    indexTexto = 0
    indexTextoFinal = 0
    name = ""
    isRichHtml = False
    isRichHtmlDone = False
    richHtml = ""
    reacaoChunk = ""
    isReacaoChunk = False
    hasFiles = False
    emojiReaction = ""
    orgidReaction = ""
    timeReaction = ""
    cvId = ""
    message = ""
    reactions = []
    reacaoChunkReady = False
    files = []
    ok = 1
    link = ""
    hrefLink = ""
    nAspas = False

    for filter in filtros:
        for line in buffer:
            if filter in line:
                filtros[filter] = 1
    for x in filtros.values():
        if x == 0:
            ok = 0

    if ok:
        isMention = False
        mention = ""
        orgid = ""
        nome = ""

        existe = False
        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("skypeguid")
                l = list(line)
                for x in range(indexTexto, indexTextoFinal):
                    if "\"" in l[x]:
                        nAspas = not nAspas
                        continue
                    if nAspas:
                        name = name + l[x + 1]
                name = name.replace("\"", "")
                sender = name
                nAspas = False
                nome = sender
            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 = 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 "http://schema.skype.com/Mention" in richHtml:
                    indexMencionado = 0
                    span = ""
                    while indexMencionado != -1:
                        # obter pelo orgid
                        isMention = True
                        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 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:
                            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):
                                hrefLink += n[x]
                            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
                    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
                    indexNomeFile = line.find("fileName", indexNomeFile) + 11
                    indexNomeFileFinal = line.find("fileType", 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, "")
                        print(richHtml)
                    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 "call-log" in line:
                # print(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")
                    displayOrig = ""
                    for x in range(line.find("displayName", ind) + 14, line.find("\"}", ind)):
                        displayOrig += l[x]
                    contactoOriginator = Contacto(displayOrig, "sem email", originator)
                    arrayContactos[originator] = contactoOriginator
                if target in arrayContactos:
                    contactoTarget = arrayContactos.get(target)
                else:
                    displayTarget = ""
                    indT = line.find("targetParticipant")
                    for x in range(line.find("displayName", indT) + 14, line.find("\"}", indT)):
                        displayTarget += l[x]
                    contactoTarget = Contacto(displayTarget, "sem email", target)
                    arrayContactos[target] = contactoTarget
                dtStart = zulu.parse(start)
                callstart = datetime.utcfromtimestamp(dtStart.timestamp())
                callstart = callstart.astimezone(tz=tz.tzlocal())
                dtEnd = zulu.parse(start)
                callEnd = datetime.utcfromtimestamp(dtEnd.timestamp())
                callEnd = callstart.astimezone(tz=tz.tzlocal())

                chamada = Chamada(contactoOriginator, str(callstart), str(callEnd), contactoTarget, state)
                arrayCallOneToOne.append(chamada)

            if isReacaoChunk and "ams_referencesa" in line:
                isReacaoChunk = False
                reacaoChunkReady = True

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

            if reacaoChunkReady:
                emojiReaction = ""
                timeReaction = ""
                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("usersa", 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 = emojiReaction
                        reaction.time = timeReaction
                        arrayReacoes.append(reaction)
                        orgidReact = ""
                        timeReaction = ""
                        reacaoChunkReady = False

        reacaoChunk = ""

        if message != "" or hasFiles:
            if "Call Log for Call" not in message:
                mensagem = MensagemCompleta()
                if isMention:
                    mensagem.isMention = True
                mensagem.mention = mention
                mensagem.message = message
                mensagem.time = time
                mensagem.sender = sender

                mensagem.cvID = cvId
                mensagem.reactions = arrayReacoes
                arrayReacoes.clear()
                mensagem.files = files
                arrayMensagens.append(mensagem)
                hasFiles = False
    def create_msg_from_history(self,event_type,interval,symbol,units,num_of_units,from_now=True,from_date=0,to_date=0): #update this to accept more ranges
        
        if from_now:
        #http://dateparser.readthedocs.io/en/latest/
            if units == 'hour':        
                raw_data=self.client.get_historical_klines(symbol, interval, "{0} hour ago UTC".format(num_of_units))
            elif units == 'day':
                raw_data=self.client.get_historical_klines(symbol, interval, "{0} day ago UTC".format(num_of_units))        
            elif units == 'week':
                raw_data=self.client.get_historical_klines(symbol, interval, "{0} week ago UTC".format(num_of_units))     
            elif units == 'month':
                raw_data=self.client.get_historical_klines(symbol, interval, "{0} month ago UTC".format(num_of_units))
            elif units == 'minute':
                raw_data=self.client.get_historical_klines(symbol, interval, "{0} minute ago UTC".format(num_of_units))         
    
        else:
            raw_data=self.client.get_historical_klines(symbol, interval,from_date,to_date)
            #klines = client.get_historical_klines("ETHBTC", Client.KLINE_INTERVAL_30MINUTE, "1 Dec, 2017", "1 Jan, 2018")
   
        list_of_msgs = list(np.zeros(len(raw_data),dtype=object))


        for i, raw_msg in enumerate(raw_data):
       
            if i%10000 == 0:
                print(i)
           
            list_of_msgs[i] =  {
                    "measurement": self.measurement_name,
                    "tags": {
                        "event_type": event_type,
                        "base_currency": symbol[:int(len(symbol)/2)],
                        "quote_currency": symbol[int(len(symbol)/2):],
                        "pair": symbol ,
                        "interval": interval
                    },
                    "time": zulu.parse(raw_msg[0]/1000.0).isoformat(),#datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),#+'Z',
                    "fields": {
                        "open": float(raw_msg[1]),
                        "close":float(raw_msg[4]),
                        "high":float(raw_msg[2]),
                        "low":float(raw_msg[3] ),
                        "high-low":float(raw_msg[2])-float(raw_msg[3]),
                        "close-open":float(raw_msg[4])-float(raw_msg[1]),
                        "volume":float(raw_msg[5]), #Base asset volume
                        "number_of_trades":int(raw_msg[8] ),
                        "quote_volume":float(raw_msg[7] ), #Quote asset volume
                        "active_buy_volume":float(raw_msg[9] ), #Taker buy base asset volume
                        "active_buy_quote_volume":float(raw_msg[10]), #Taker buy quote asset volume
                        "gain":-1000,
                        "lose":-1000,
                        "avg_gain":-1000,
                        "avg_lose":-1000,
                        "RSI":-1000,                   
                        "MACD":-1000,
                        "KDJ":-1000,
                        "DMI":-1000,
                        "OBV":-1000,
                        "MTM":-1000,
                        "EMA":-1000,
                        "VWAP":-1000,
                        "AVL":-1000,
                        "TRIX":-1000,
                        "StochRSI":-1000,
                        "EMV":-1000,
                        "WR":-1000,
                        "BOLL":-1000,
                        "SAR":-1000,
                        "CCI":-1000,
                        "MA":-1000,
                        "VOL":-1000                    
                    
                    }
                }
        return list_of_msgs      
    def from_unix_to_date(self, date_unix, with_Z=True):
        string_date = zulu.parse(date_unix).isoformat()
        if with_Z:
            string_date = string_date.replace(string_date[-6:], 'Z')

        return string_date
Example #23
0
    def update_host_status(
        self, event, event_type, host_info, host_ref, output, status, unique_id_event
    ):
        """
        Update host to new status

        :param event: Event data
        :param event_type: Event type
        :param host_info: Host information
        :param host_ref: Host reference
        :param output: Output
        :param status: Status
        :param unique_id_event: Unique ID event
        """

        # Update old host feature
        arcgis_updates = {
            "objectid": host_info["objectId"],
            "endtime": zulu.parse(event["timestamp"]).timestamp() * 1000,
        }
        response = self.arcgis_processor.update_feature(
            host_info["longitude"],
            host_info["latitude"],
            arcgis_updates,
            config.LAYER["hosts"],
        )

        if "success" in response:
            gis_kleur = (
                status if event_type == "HOST" else (status + 9)
            )  # For colouring in GIS
            start_time = (
                zulu.parse(event["timestamp"]).timestamp() * 1000
            )  # Format timestamp

            # Add new host feature
            attributes = {
                "sitename": event["sitename"],
                "hostname": event["hostname"],
                "hostgroups": host_info["hostgroups"],
                "bssglobalcoverage": host_info["bssglobalcoverage"],
                "bsshwfamily": host_info["bsshwfamily"],
                "bsslifecyclestatus": host_info["bsslifecyclestatus"],
                "giskleur": gis_kleur,
                "status": status,
                "type": event_type,
                "event_output": output,
                "starttime": start_time,
            }

            response = self.arcgis_processor.add_feature(
                host_info["longitude"],
                host_info["latitude"],
                attributes,
                config.LAYER["hosts"],
            )

            if "success" in response:
                host_ref.update(
                    {
                        "objectId": response["objectId"],
                        "status": status,
                        "type": event_type,
                        "event_output": output,
                        "starttime": zulu.parse(event["timestamp"]).timestamp() * 1000,
                    }
                )
                logging.info(
                    f"Successfully updated host feature with event id: {unique_id_event}"
                )
            else:
                logging.error(
                    f"Error when adding host feature for event: {json.dumps(response)}"
                )
        else:
            logging.error(
                f"Error when updating host feature for event: {json.dumps(response)}"
            )
Example #24
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()