상세 컨텐츠

본문 제목

[스파르타 코딩클럽] 파이썬으로 사진 기록하기 프로젝트 다시 살리기!!

본문

예전에 만들었던 프로젝트인데 도메인 만료 에다가 API기간도 만료되고 서비스도 종료되서 프로젝트를 다시 불러 올 수 없었다.

그래도 열심히 만들었는데 내버려 두자니 아까워서 다시 살렸다.

 

컨셉을 바꿔 영화가 아니라 마음에 드는 사진을 기록할 수 있게 다시 재구성 하였다.

 

처음에 사진 링크를 넣을 때 계속 인코딩이 안된 화면만 나와서 단위 테스트로 계속 타고 올라가서 어디서 부터 문제 였는지 살펴본 후,

문제 점을 찾았다.

파이썬으로 사이트 크롤링을 할 때 아래 있는 og태그가 다 일치 해야한다.

특히 사진을 가지고 오는게 큰 목적이라 사이트 전체를 분석해준다, 사진만 나온 페이지가 아니라 사진이 속해 있는 사이트도 같이 나와야 하는것.

 

왼쪽은 사진 주소만 나와 있는것이고 오른쪽은 사진을 제공해준 사이트 주소도 같이 나와 있는것이다.

 

 

왼쪽 주소를 넣어주면 사이트 주소와 받을 그림의 타이틀이 없어 계속 에러가 아닌 해석이 안된 화면만 보내주고 있는 것.

오른쪽 주소를 넣어주니 사진에 관련된 모든 정보가 들어와 보여준다.

 

아래는 배포하기 위해 터미널에 입력한 명령어이다.

업데이트 관련해서도 그렇고 AWS권한 설정할 수 있는 모드 명령어가 들어 있다 참고 하시길.

더보기

Last login: Thu Jun 13 22:14:41 on console

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
APPLEui-MacBook-Pro:~ apple$ ls
Applications
Creative Cloud Files
Creative Cloud Files (archived) (1)
Desktop
Documents
Downloads
Dropbox
KakaoTalk_Photo_2023-02-25-23-12-08.jpeg
Library
Movies
Music
Pictures
Public
PycharmProjects
VirtualBox VMs
java_error_in_idea_1105.log
nohup.out
sparta
APPLEui-MacBook-Pro:~ apple$ sudo chmod 400 /Users/apple/Desktop/share_mykey.pem
Password:
APPLEui-MacBook-Pro:~ apple$ ssh -i /Users/apple/Desktop/share_mykey.pem ubuntu@13.125.168.114
Welcome to Ubuntu 24.04 LTS (GNU/Linux 6.8.0-1009-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Thu Jun 13 13:27:10 UTC 2024

  System load:  0.16              Processes:             106
  Usage of /:   38.4% of 6.71GB   Users logged in:       0
  Memory usage: 32%               IPv4 address for enX0: 172.31.9.192
  Swap usage:   0%

 * Ubuntu Pro delivers the most comprehensive open source security and
   compliance features.

   https://ubuntu.com/aws/pro

Expanded Security Maintenance for Applications is not enabled.

34 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


Last login: Sat Jun  8 12:45:43 2024 from 13.209.1.60
ubuntu@ip-172-31-9-192:~$ ls
nohup.out  pythonProject  toyproject
ubuntu@ip-172-31-9-192:~$ cd pythonProject
ubuntu@ip-172-31-9-192:~/pythonProject$ ls
app.py  hello.py  myenv  nohup.out  templates  venv
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo apt-get update
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Hit:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-backports InRelease
Get:4 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [164 kB]
Get:5 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates/main Translation-en [45.5 kB]
Get:6 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [63.1 kB]
Get:7 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates/universe Translation-en [24.2 kB]
Get:8 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Packages [70.1 kB]
Get:9 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates/restricted Translation-en [14.3 kB]
Get:10 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Packages [2996 B]
Get:11 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]             
Get:12 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [143 kB]
Get:13 http://security.ubuntu.com/ubuntu noble-security/main Translation-en [37.7 kB]
Get:14 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages [42.9 kB]
Get:15 http://security.ubuntu.com/ubuntu noble-security/universe Translation-en [16.6 kB]
Get:16 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Packages [63.2 kB]
Get:17 http://security.ubuntu.com/ubuntu noble-security/restricted Translation-en [13.3 kB]
Fetched 952 kB in 4s (265 kB/s)                                 
Reading package lists... Done
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo apt-get install -y python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-pip is already the newest version (24.0+dfsg-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 34 not upgraded.
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
ubuntu@ip-172-31-9-192:~/pythonProject$ python app.py
Traceback (most recent call last):
  File "/home/ubuntu/pythonProject/app.py", line 2, in <module>
    from flask import Flask, render_template, request, jsonify
ModuleNotFoundError: No module named 'flask'
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo apt-get update
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble InRelease
Hit:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu noble-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo apt-get install -y python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-pip is already the newest version (24.0+dfsg-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 34 not upgraded.
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
ubuntu@ip-172-31-9-192:~/pythonProject$ python app.py
Traceback (most recent call last):
  File "/home/ubuntu/pythonProject/app.py", line 2, in <module>
    from flask import Flask, render_template, request, jsonify
ModuleNotFoundError: No module named 'flask'
ubuntu@ip-172-31-9-192:~/pythonProject$ pip install flask
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
ubuntu@ip-172-31-9-192:~/pythonProject$ sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-venv is already the newest version (3.12.3-0ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 34 not upgraded.
ubuntu@ip-172-31-9-192:~/pythonProject$ python3 -m venv venv
ubuntu@ip-172-31-9-192:~/pythonProject$ source venv/bin/activate
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ pip install flask
Requirement already satisfied: flask in ./venv/lib/python3.12/site-packages (3.0.3)
Requirement already satisfied: Werkzeug>=3.0.0 in ./venv/lib/python3.12/site-packages (from flask) (3.0.3)
Requirement already satisfied: Jinja2>=3.1.2 in ./venv/lib/python3.12/site-packages (from flask) (3.1.4)
Requirement already satisfied: itsdangerous>=2.1.2 in ./venv/lib/python3.12/site-packages (from flask) (2.2.0)
Requirement already satisfied: click>=8.1.3 in ./venv/lib/python3.12/site-packages (from flask) (8.1.7)
Requirement already satisfied: blinker>=1.6.2 in ./venv/lib/python3.12/site-packages (from flask) (1.8.2)
Requirement already satisfied: MarkupSafe>=2.0 in ./venv/lib/python3.12/site-packages (from Jinja2>=3.1.2->flask) (2.1.5)
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ python app.py
 * Serving Flask app 'app'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:3000
 * Running on http://172.31.9.192:3000
Press CTRL+C to quit
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 953-705-353
125.177.176.180 - - [13/Jun/2024 13:34:59] "GET / HTTP/1.1" 200 -
125.177.176.180 - - [13/Jun/2024 13:35:06] "GET /movie HTTP/1.1" 200 -
14.33.9.113 - - [13/Jun/2024 13:38:02] "GET / HTTP/1.1" 200 -
14.33.9.113 - - [13/Jun/2024 13:38:03] "GET /favicon.ico HTTP/1.1" 404 -
14.33.9.113 - - [13/Jun/2024 13:38:10] "GET /movie HTTP/1.1" 200 -
125.177.176.180 - - [13/Jun/2024 13:45:45] "GET / HTTP/1.1" 200 -
125.177.176.180 - - [13/Jun/2024 13:45:46] "GET /favicon.ico HTTP/1.1" 404 -
125.177.176.180 - - [13/Jun/2024 13:45:52] "GET /movie HTTP/1.1" 200 -
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ nohup python app.py &
[1] 20822
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ nohup: ignoring input and appending output to 'nohup.out'
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ ps -ef | grep 'python app.py' | awk '{print $2}' | xargs kill
kill: (20842): No such process
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ ps -ef | grep 'python app.py' | awk '{print $2}' | xargs kill
kill: (20852): No such process
[1]+  Done                    nohup python app.py
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ ps -ef | grep 'python app.py'
ubuntu     20857   19832  0 14:06 pts/0    00:00:00 grep --color=auto python app.py
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ nohup python app.py &
[1] 20863
(venv) ubuntu@ip-172-31-9-192:~/pythonProject$ nohup: ignoring input and appending output to 'nohup.out'

반응형

관련글 더보기

댓글 영역