diff --git a/Zadanie_4_3_b/README.md b/Zadanie_4_3_b/README.md index 172323a..0b45d50 100644 --- a/Zadanie_4_3_b/README.md +++ b/Zadanie_4_3_b/README.md @@ -1,4 +1,4 @@ -1) Aby kod uruchomił się poprawnie należy uzupełnić zmienne: +1) Aby kod uruchomił się poprawnie należy uzupełnić zmienne w pliku aws.py: - aws_access_key_id (należy znaleźć na stronie AWS) - aws_secret_access_key (należy znaleźć na stronie AWS) - aws_session_token (należy znaleźć na stronie AWS) diff --git a/Zadanie_4_3_b/aws.py b/Zadanie_4_3_b/aws.py index a9c5eb9..f012f71 100644 --- a/Zadanie_4_3_b/aws.py +++ b/Zadanie_4_3_b/aws.py @@ -1,9 +1,9 @@ # niezbędna konfiguracja danych dostępowych, pamiętaj aby nigdy jej nie udostępniać publicznie -aws_access_key_id='' -aws_secret_access_key='' -aws_session_token='' +aws_access_key_id="" +aws_secret_access_key="" +aws_session_token="" VPC='' -ID='' +ID='s-444376' # biblioteka dostępowa do AWS diff --git a/Zadanie_5.2_5.3/.Rhistory b/Zadanie_5.2_5.3/.Rhistory new file mode 100644 index 0000000..e69de29 diff --git a/Zadanie_5.2_5.3/Dockerfile b/Zadanie_5.2_5.3/Dockerfile new file mode 100644 index 0000000..eaaf007 --- /dev/null +++ b/Zadanie_5.2_5.3/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.8 +COPY api.py requirements.txt ./ +RUN apt-get update +RUN apt-get install -y default-jdk +RUN pip install -r requirements.txt +EXPOSE 80:8000/tcp +CMD python api.py \ No newline at end of file diff --git a/Zadanie_5.2_5.3/api.py b/Zadanie_5.2_5.3/api.py new file mode 100644 index 0000000..693a5a0 --- /dev/null +++ b/Zadanie_5.2_5.3/api.py @@ -0,0 +1,40 @@ +from fastapi import FastAPI, UploadFile +from fastapi.middleware.cors import CORSMiddleware +from tika import parser +import uvicorn +import re + +#Celem jest wyekstrahowanie nazwy sprzedawcy, jego numeru NIP oraz kwoty łącznej brutto faktury +def parse(pdf): + content = parser.from_buffer(pdf) + content = content['content'].split('\n') + content = [c for c in content if c != ''] + total = float(re.findall(r'\d+[.]\d+', list(filter(lambda x: 'Razem' in x, content))[0])[-1]) + content = content[content.index('Sprzedawca:') : content.index('Nabywca:')] + seller = content[1] + nip = content[-1].replace('NIP: ', '') + return { + 'vat_id' : nip, + 'address' : seller, + 'total' : total + } + + +app = FastAPI() + +origins = ["*"] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +@app.post('/invoice') +async def root(file: UploadFile): + return parse(file.file.read()) + + +uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file diff --git a/Zadanie_5.2_5.3/dane/AFV 1_05_2021.pdf b/Zadanie_5.2_5.3/dane/AFV 1_05_2021.pdf new file mode 100644 index 0000000..6ae4d25 Binary files /dev/null and b/Zadanie_5.2_5.3/dane/AFV 1_05_2021.pdf differ diff --git a/Zadanie_5.2_5.3/dane/AFV 3_05_2021.pdf b/Zadanie_5.2_5.3/dane/AFV 3_05_2021.pdf new file mode 100644 index 0000000..ae57e0d Binary files /dev/null and b/Zadanie_5.2_5.3/dane/AFV 3_05_2021.pdf differ diff --git a/Zadanie_5.2_5.3/dane/BFV 3_05_2021.pdf b/Zadanie_5.2_5.3/dane/BFV 3_05_2021.pdf new file mode 100644 index 0000000..92f9b4e Binary files /dev/null and b/Zadanie_5.2_5.3/dane/BFV 3_05_2021.pdf differ diff --git a/Zadanie_5.2_5.3/index.html b/Zadanie_5.2_5.3/index.html new file mode 100644 index 0000000..39b714e --- /dev/null +++ b/Zadanie_5.2_5.3/index.html @@ -0,0 +1,22 @@ + + + + Chmuuuuuuurki + + + +

+ + \ No newline at end of file diff --git a/Zadanie_5.2_5.3/main.py b/Zadanie_5.2_5.3/main.py new file mode 100644 index 0000000..f8db611 --- /dev/null +++ b/Zadanie_5.2_5.3/main.py @@ -0,0 +1,55 @@ +aws_access_key_id='' +aws_secret_access_key='' +aws_session_token='' +VPC='' +ID='444376' + +import boto3 +ec2 = boto3.resource( + 'ec2', + region_name='us-east-1', + aws_access_key_id=aws_access_key_id, + aws_secret_access_key=aws_secret_access_key, + aws_session_token=aws_session_token, +) + +key_pair = ec2.create_key_pair( + KeyName=ID+'-KEY-PAIR', + KeyType='ed25519', + KeyFormat='pem', +) + +security_group = ec2.create_security_group( + Description=ID+'-GROUP', + GroupName=ID+'-GROUP', + VpcId=VPC +) + +inbound_rules = security_group.authorize_ingress( + GroupId=security_group.group_id, + CidrIp='0.0.0.0/0', + IpProtocol='tcp', + FromPort=80, + ToPort=80 +) + +instances = ec2.create_instances( + ImageId='ami-0b5eea76982371e91', + MinCount=1, + MaxCount=1, + InstanceType='t2.micro', + KeyName=key_pair.name, + UserData=f''' + #!/bin/bash + sudo yum update -y + sudo yum install git -y + git clone git clone https://git.wmi.amu.edu.pl/s444376/DPZC_Ola.git + cd DPZC_Ola/Zadanie_5.2_5.3 + sudo yum install docker -y + sudo service docker start + sudo usermod -a -G docker ec2-user + sudo docker build -t invoice . + sudo docker run -d -p 80:8000 -t invoice + ''', + SecurityGroups=[security_group.group_name] +) \ No newline at end of file diff --git a/Zadanie_5.2_5.3/requirements.txt b/Zadanie_5.2_5.3/requirements.txt new file mode 100644 index 0000000..b6fd337 --- /dev/null +++ b/Zadanie_5.2_5.3/requirements.txt @@ -0,0 +1,4 @@ +fastapi +tika +uvicorn +python-multipart \ No newline at end of file diff --git a/Zadanie_5.2_5.3/website-bucket-policy.json b/Zadanie_5.2_5.3/website-bucket-policy.json new file mode 100644 index 0000000..1857bb0 --- /dev/null +++ b/Zadanie_5.2_5.3/website-bucket-policy.json @@ -0,0 +1,13 @@ +{ + "Id": "MyPolicy", + "Version": "2023-01-22", + "Statement": [ + { + "Sid": "PublicReadForGetBucketObjects", + "Effect": "Allow", + "Principal": "*", + "Action": "s3:GetObject", + "Resource": "arn:aws:s3:::olusza/*" + } + ] + } \ No newline at end of file