Beispiel #1
0
def find_snomedct_server(term):
    apikey = "ca310f05-53e6-4984-82fd-8691dc30174e"
    AuthClient = Authentication(apikey)
    version = "2017AB"
    tgt = AuthClient.gettgt()
    query = {'ticket': AuthClient.getst(tgt), 'targetSource': 'SNOMEDCT_US'}
    base_uri = "https://uts-ws.nlm.nih.gov/rest"
    search_uri = "/search/current?string="
    content_uri = "/content/current/CUI/"
    source = "&sabs=SNOMEDCT_US"
    search_type = '&searchType=words'
    path = base_uri + search_uri + term + search_type + source
    r = requests.get(path, params=query)
    code, name, semantic = "", "", ""
    try:
        items = json.loads(r.text)
        pprint(items['result']['results'])
        code, name = select_code(items['result']['results'], term)
        if code != "":
            path2 = base_uri + content_uri + code
            tgt2 = AuthClient.gettgt()
            query2 = {
                'ticket': AuthClient.getst(tgt2),
                'targetSource': 'SNOMEDCT_US'
            }
            r2 = requests.get(path2, params=query2)
            try:
                items2 = json.loads(r2.text)
                semantic = items2['result']['semanticTypes'][0]['name']
            except json.decoder.JSONDecodeError:
                semantic = "UNKNOWN"
    except json.decoder.JSONDecodeError:
        code, name = "", ""
    return code, name, semantic
Beispiel #2
0
 def get(self):
     activity = Activity()
     from Authentication import Authentication
     authentication = Authentication(users)
     print(activity)
     return ({
         "activity": str(activity),
         "user": str(authentication),
         "location": "home"
     })
    def handle(self):
        """
        Handle requests from the clients.
        :return:
        """
        global auth_dict, nonce_dict, crypto_service, password_hash_dict, user_addr_dict, chatting_service
        msg = self.request[0]
        sock = self.request[1]
        # get auth instance for client
        if self.client_address not in auth_dict:
            try:
                _, msg_parts = PacketOrganiser.process_packet(msg)
            except:
                return
            if msg_parts[0] != c.GREETING:
                return
            # new client, create an auth entry in the auth dictionary
            auth_dict[self.client_address] = Authentication(
                self.client_address, crypto_service, password_hash_dict)
        else:
            auth = auth_dict[self.client_address]
            if not PacketOrganiser.isValidTimeStampSeconds(
                    auth.timestamp, c.KEEP_ALIVE_TIME):
                auth_dict.pop(self.client_address)

        cur_auth = auth_dict[self.client_address]
        assert isinstance(cur_auth, Authentication)
        rep = None
        if not cur_auth.is_auth():
            rep = cur_auth.process_request(msg, user_addr_dict)

        else:
            # get decrypted msg
            dec_msg = crypto_service.sym_decrypt(cur_auth.dh_key, msg)
            n, msg_ps = PacketOrganiser.process_packet(dec_msg)
            auth_dict[
                self.
                client_address].timestamp = PacketOrganiser.get_new_timestamp(
                )  # update timestamp
            rep = chatting_service.get_response(self.client_address, msg_ps)
            if rep is not None:
                rep = PacketOrganiser.prepare_packet(rep, n)
                rep = crypto_service.sym_encrypt(cur_auth.dh_key, rep)

        try:
            if rep is not None:
                sys.stdout.flush()
                sock.sendto(rep, self.client_address)
            elif cur_auth.is_auth():
                cur_auth.loginfailures += 1
        except socket.error:
            print(c.FAIL_MSG_FWD)
            return
 def __init__(self, clientId, data, verifykey, apiEndPoint):
     self.message = data
     self.sessionkey = verifykey
     self.apiEndPoint = apiEndPoint
     self.splitUrl = apiEndPoint.split('/')
     self.auth = Authentication()
     self.master = Master()
     self.admin = Admin()
     self.role = roleManage()
     self.attendance = attendanceManage()
     self.project = projectManage()
     self.labourer = labbourerManage()
     self.labclass = labourerClass()
     self.shift = shiftManage()
     self.log = Logger()
     self.paymentDesk = paymentDesk()
     self.clientId = clientId
Beispiel #5
0
def get_umls_ticket2(tgt=tgt, AuthClient=AuthClient, apikey=umls_api):
    """
    Get a single use ticket for the UMLS REST services.
    It is supposed that an Author Client and a Ticket
    Granting Service have already been set-up in case
    the apikey = None. If an api-key is given, create the
    above needed instances and generate a new ticket.
    Input:
        - apikey: str,
        UMLS REST services api-key. Default is None and
        the already establised service is used
    Output:
        - string of the generated ticket
    """

    # Get ticket from the already establised service
    if not (tgt) and not (AuthClient):
        AuthClient = Authentication(umls_api)
        tgt = AuthClient.gettgt()
    return AuthClient.getst(tgt)
 def Api(self):
     self.judger = Authentication()
Beispiel #7
0
Utility functions.

"""

import time
import logging
import requests
import json
from config import settings
from Authentication import Authentication

# API-kEY FOR UMLS REST TICKET SERVICES
umls_api = settings['apis']['umls']
# UMLS REST SERVICES INITIALIZATION OF CLIENT AND TICKET
# GRANTING SERVICE TO BE USED IN ALL CASES
AuthClient = Authentication(umls_api)
tgt = AuthClient.gettgt()

logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)


def get_umls_ticket2(tgt=tgt, AuthClient=AuthClient, apikey=umls_api):
    """
    Get a single use ticket for the UMLS REST services.
    It is supposed that an Author Client and a Ticket
    Granting Service have already been set-up in case
    the apikey = None. If an api-key is given, create the
    above needed instances and generate a new ticket.
    Input:
        - apikey: str,
Beispiel #8
0
 def __init__(self):
     self.log = Logger()
     self .authen = Authentication()
Beispiel #9
0
def auth(callback: Callable, request: request, admin: bool = True, id_user: bool = False) -> tuple:
	authentication = Authentication(admin)
	if (authentication.is_authenticated(request)):
		return callback(authentication.get_id_user()) if id_user else callback()
	else:
		return Response(ResponseType.INVALID_CREDENTIALS).message()
Beispiel #10
0
import sys

# My libraries
from Authentication import Authentication
from HarvestingTweets import BasicHarvestTweets
from GatherTweets import GatherTweetsByWords, GatherTweetsByAccounts

if __name__ == "__main__":
    data_path = "/home/user/TwitterData"
    auth = Authentication()

    if sys.argv[1] == "words":
        gtw = GatherTweetsByWords(BasicHarvestTweets(auth.auth, auth.api),
                                  ["startups", "machinelearning"])
        gtw.gatherTweets(data_path, "words")

    elif sys.argv[1] == "accounts":
        gta = GatherTweetsByAccounts(BasicHarvestTweets(auth.auth, auth.api),
                                     ["Forbes", "businessinsider"])
        gta.gatherTweets(data_path, "accounts")

    else:
        print(sys.argv[1] + " not implemented...")
Beispiel #11
0
                writer = csv.writer(f, delimiter=";")
                writer.writerow(
                    [text, tags, user, time, location, coordinates])

                # Increment counter
                MyStreamListener.counter += 1

    def on_error(self, status_code):
        print(status_code)
        return False


if __name__ == "__main__":

    FILE_NAME = "#CoronaHoax.csv"
    api = Authentication(isApp=False).get_api()
    auth = api.auth
    myStreamListener = MyStreamListener(FILE_NAME)
    myStream = tweepy.Stream(auth=auth, listener=myStreamListener)

    try:
        print('Start streaming...')
        myStream.filter(languages=['en'],
                        track=[
                            "#CoronaHoax", "#CovidHoax", "#coronahoax",
                            "#covidhoax", "plandemic", "Plandemic",
                            "#scamdemic", "#Scamdemic", "#SCAMDEMIC"
                        ])

    except KeyboardInterrupt:
        print("Stopped.")
 def __init__(self):
     self.auth = Authentication()
     self.log = Logger()
     self.rejx = dataVerify()
 def login(self, username, password):
     result = Authentication().login(username, password)
     return result
 def __init__(self):
     self.authentication = Authentication()