Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
crab85193 committed Dec 14, 2023
0 parents commit 10bf311
Show file tree
Hide file tree
Showing 15 changed files with 382 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Bug Report
description: バグに関するIssueのテンプレート
title: "[Bug]: "
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: what-happened
attributes:
label: What happened?
description: どのような問題が発生しましたか?
placeholder: 問題が発生した時の情報を記述して下さい。
validations:
required: true
- type: textarea
id: logs
attributes:
label: 関連するログの出力
description: 関連するログ出力をコピー&ペーストしてください。これは自動的にコードにフォーマットされますので、バックティックは必要ありません。
render: shell
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Feature Request
description: 新機能に関するIssueのテンプレート
title: "[Feature]: "
body:
- type: markdown
attributes:
value: |
Thanks for suggesting the new feature!
- type: textarea
id: purpose
attributes:
label: 目的
description: 新機能を実装する目的について記述して下さい
placeholder: ご記入ください
validations:
required: true
- type: textarea
id: tasks
attributes:
label: やること
description: 新機能を実装する上で取り組みことを記述して下さい
placeholder: |
* 〇〇を実装する
* 〇〇を作成する
validations:
required: true
- type: textarea
id: notes
attributes:
label: その他伝達事項
description: 注意事項や伝達事項、メモがあれば記述して下さい
validations:
required: false
35 changes: 35 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// pull request発行の際は '//'が書かれている行を削除して下さい

## Ticket / Issue Number

//チケット番号などを記入してください

//- #3
//なければ「チケットなし」と記入して下さい

## What's changed

//このプルリクは何をしたのかを記入してください。画像とテキストを使って説明するのがおすすめです。

//* ホームページのUIを調整しました
//* Primary Colorを`#0969DA`へ変更しました(@ianchen0419 確認お願いします)
//* Bugを修復しました :+1:
//* デプロイしました([デプロイ先](https://pages.github.com/)

## Todo List

//今回のプルリクはまだやっていないことや、将来やる予定の事項を記入してください

//- [x] デザイナーに確認してもらいます
//- [ ] iOS 16のデバイスにテストします
//- [ ] テストケースを書きます

## Check List

- [ ] エラーや警告は出ませんでした
- [ ] `docker-compose -f docker-compose.dev.yml up -d`を使ってコンテナの起動を確認しました
- [ ] 開発環境で`localhost:8000`にアクセスしてサイトの動作確認を行いました

## Remark

//補足事項があれば記入してください
22 changes: 22 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
name: id_github_actions_rsa
known_hosts: ${{ secrets.KNOWN_HOSTS }}
config: ${{ secrets.SSH_CONFIG }}
- name: Check out code
uses: actions/checkout@v2
- name: Deploy with rsync
run: |
ls -a
rsync -auvPz ./ ${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/tely-store-manager/
ssh ${{ secrets.SSH_HOST }} 'cd /home/$USER/tely-store-manager; docker-compose -f docker-compose.prod down;docker-compose -f docker-compose.prod up -d --build'
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store

.env
.env.prod
.env.dev

.venv/

static/*
!static/.gitkeep
3 changes: 3 additions & 0 deletions containers/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.21-alpine

COPY containers/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
8 changes: 8 additions & 0 deletions containers/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen 80;
server_name 0.0.0.0;

location /static/ {
alias /static/;
}
}
13 changes: 13 additions & 0 deletions containers/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.11.0

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /code
COPY requirements.txt /code/

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

COPY . /code/

32 changes: 32 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.9"

services:
python:
container_name: python
build:
context: .
dockerfile: containers/python/Dockerfile
volumes:
- .:/code
tty: true
env_file:
- .env.dev
networks:
- shared_network
image_web:
container_name: image_web
build:
context: .
dockerfile: containers/nginx/Dockerfile
volumes:
- ./static:/static
ports:
- 80:80
networks:
- shared_network
volumes:
static:

networks:
shared_network:
external: true
26 changes: 26 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3.9"

services:
python:
container_name: python
build:
context: .
dockerfile: containers/python/Dockerfile
restart: unless-stopped
volumes:
- .:/code
tty: true
env_file:
- .env.dev
image_web:
container_name: image_web
build:
context: .
dockerfile: containers/nginx/Dockerfile
restart: unless-stopped
volumes:
- ./static:/static
ports:
- 80:80
volumes:
static:
13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
certifi==2023.11.17
charset-normalizer==3.3.2
click==8.1.7
decorator==5.1.1
future==0.18.3
geocoder==1.38.1
googlemaps==4.10.0
idna==3.6
mysqlclient==2.2.0
ratelim==0.1.6
requests==2.31.0
six==1.16.0
urllib3==2.1.0
76 changes: 76 additions & 0 deletions src/google_api_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import os
import requests
import googlemaps
import geocoder

class GoogleAPIController():
def __init__(self):
self.__gmaps = googlemaps.Client(key=os.environ.get("GOOGLE_API_KEY"))

def download_place_photo(self, photo_reference, file_name=None):
base_url = "https://maps.googleapis.com/maps/api/place/photo"
max_width = 400

params = {
"maxwidth": max_width,
"photoreference": photo_reference,
"key": os.environ.get("GOOGLE_API_KEY")
}

response = requests.get(base_url, params=params, stream=True)

if response.status_code == 200:
if file_name:
f_name = os.environ.get("SAVE_IMG_DIR") + "/" + file_name
else:
f_name = os.environ.get("SAVE_IMG_DIR") + "/" + photo_reference + ".jpg"

with open(f_name, 'wb') as file:
for chunk in response.iter_content(chunk_size=128):
file.write(chunk)
else:
print("Error: Unable to download the image.")

def get_store_photo_url(self, photo_reference):
self.download_place_photo(photo_reference)
return f"{os.environ.get('IMAGE_SERVER_PROTOCOL')}://{os.environ.get('IMAGE_SERVER_ADDRESS')}/static/{photo_reference}.jpg"

def search_store(self, keyword):
location = geocoder.ip('me').latlng
search_response = self.__gmaps.places_nearby(location=location, keyword=keyword, radius=50000, language="ja")
stores_info = []

for place in search_response['results']:
store_info = {}
try:
store_info["place_id"] = place["place_id"]
store_info["name"] = place["name"]
except Exception as e:
print(e)
continue
try:
store_info["type"] = place["types"]
except Exception as e:
store_info["type"] = []
try:
store_info["open"] = place["opening_hours"]["open_now"]
except Exception as e:
store_info["open"] = None
try:
store_info["photos"] = self.get_store_photo_url(place["photos"][0]["photo_reference"])
except Exception as e:
print(e)
store_info["photos"] = ""
try:
store_info["rating"] = place["rating"]
except Exception as e:
store_info["rating"] = None
try:
store_info["price_level"] = place["price_level"]
except Exception as e:
store_info["price_level"] = None

stores_info.append(store_info)

return stores_info

32 changes: 32 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import shutil
from store_manager import StoreManager
from google_api_controller import GoogleAPIController

def main():
store_manager = StoreManager()
api = GoogleAPIController()

target_dir = '../static'

shutil.rmtree(target_dir)
os.mkdir(target_dir)

store_manager.delete_all()

results = api.search_store("飲食店")

for result in results:
store_manager.insert(
result["place_id"],
result["name"],
" ".join(result["type"]),
result["open"],
result["photos"],
result["rating"],
result["price_level"]
)


if __name__ == "__main__":
main()
Loading

0 comments on commit 10bf311

Please sign in to comment.