Skip to content

Commit

Permalink
Merge pull request #4 from ThreeDify/app-secret
Browse files Browse the repository at this point in the history
Add app id and secret in api requests.
  • Loading branch information
silwalanish authored Jan 16, 2021
2 parents 999d8cd + 780f4f7 commit 2982a1d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
API_BASE_URL=http://localhost:3000

SFM_IMPLEMENTATION=OPENSFM|THREEDIFY
APP_ID=<APP_ID>
APP_SECRET=<APP_SECRET>

BATCH_SIZE=10
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ThreeDify is a online platform where you can upload images and create a 3D recon
| ----------------------------- | ------------------------------------------------ |
| API_BASE_URL | API base url e.g. http://localhost |
| SFM_IMPLEMENTATION | SfM implementation to use. (OPENSFM/THREEDIFY) |
| APP_ID | App ID for ThreeDify api. |
| APP_SECRET | App secret for ThreeDify api. |
| BATCH_SIZE | No. of reconstruction to process at a time. |

# Setup
1. Install `python-3.8` and `pip`.
Expand Down
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from threedify_sfm.SfM import SfM
from threedify_sfm.DataSet import DataSet
from threedify_sfm.utils.opensfm import OpenSfM
from threedify_sfm.constants import SFM_IMPLEMENTATION
from threedify_sfm.constants import SFM_IMPLEMENTATION, BATCH_SIZE
from threedify_sfm.utils.reconstructions import (
fetch_reconstructions,
reconstruction_failed,
Expand All @@ -17,7 +17,7 @@


def main():
reconstructions = fetch_reconstructions()
reconstructions = fetch_reconstructions(BATCH_SIZE)

for reconstruction in reconstructions:
try:
Expand Down
11 changes: 9 additions & 2 deletions src/threedify_sfm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

load_dotenv()

API_BASE_URL = os.getenv("API_BASE_URL")
API_BASE_URL = os.environ["API_BASE_URL"]

DOWNLOAD_PATH = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "../../", "data"
)

SFM_IMPLEMENTATION = os.getenv("SFM_IMPLEMENTATION", "THREEDIFY").upper()
SFM_IMPLEMENTATION = os.environ.get("SFM_IMPLEMENTATION", "THREEDIFY").upper()

API_HEADERS = {
"x-threedify-app-id": os.environ["APP_ID"],
"x-threedify-app-secret": os.environ["APP_SECRET"],
}

BATCH_SIZE = int(os.environ.get("BATCH_SIZE", 10))
4 changes: 2 additions & 2 deletions src/threedify_sfm/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests

from threedify_sfm.models.Image import Image
from threedify_sfm.constants import API_BASE_URL
from threedify_sfm.constants import API_BASE_URL, API_HEADERS

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand All @@ -20,7 +20,7 @@ def download(image: Image, path):
download_url = "{}/{}".format(IMAGE_BASE_URL, filename)

logger.info("Downloading image: %s", download_url)
response = requests.get(download_url, stream=True)
response = requests.get(download_url, stream=True, headers=API_HEADERS)

if response.status_code == 200:
download_file = os.path.join(path, filename)
Expand Down
14 changes: 10 additions & 4 deletions src/threedify_sfm/utils/reconstructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests

from threedify_sfm.constants import API_BASE_URL
from threedify_sfm.constants import API_BASE_URL, API_HEADERS
from threedify_sfm.models.Reconstruction import Reconstruction

logger = logging.getLogger(__name__)
Expand All @@ -31,7 +31,9 @@ def fetch_reconstructions(limit: int = 10) -> List[Reconstruction]:

try:
logger.info("Fetching reconstructions.")
response = requests.put(RECONSTRUCTIONS_API_URL, params=params)
response = requests.put(
RECONSTRUCTIONS_API_URL, params=params, headers=API_HEADERS
)
if response.status_code == 200:
reconstructions = response.json()
logger.info("Fetched %d reconstructions.", len(reconstructions))
Expand All @@ -55,7 +57,9 @@ def reconstruction_failed(reconstruction: Reconstruction):
"""
try:
logger.info("Reseting reconstruction: %d", reconstruction.id)
response = requests.put(RECONSTRUCTIONS_FAILED_URL.format(reconstruction.id))
response = requests.put(
RECONSTRUCTIONS_FAILED_URL.format(reconstruction.id), headers=API_HEADERS
)
if response.status_code == 200:
logger.info("Reconstrucion %d reset completed.", reconstruction.id)
else:
Expand All @@ -80,7 +84,9 @@ def reconstruction_success(reconstruction: Reconstruction, file_path: str):
"Uploading reconstruction output (%s) for: %d", file_path, reconstruction.id
)
response = requests.put(
RECONSTRUCTIONS_SUCCESS_URL.format(reconstruction.id), files=files
RECONSTRUCTIONS_SUCCESS_URL.format(reconstruction.id),
files=files,
headers=API_HEADERS,
)
if response.status_code == 200:
logger.info(
Expand Down

0 comments on commit 2982a1d

Please sign in to comment.