Skip to content

Commit

Permalink
Modify functions to use timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
dalonsoa committed Dec 20, 2023
1 parent da3266b commit 49cd614
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions importing/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_last_uploaded_date(station_id, var_code):
return datetime


def preformat_matrix(source_file, file_format):
def preformat_matrix(source_file, file_format, timezone: str):
"""
First step for importing data. Works out what sort of file is being read and adds
standardised columns for date and datetime (str). This is used in construct_matrix.
Expand Down Expand Up @@ -152,7 +152,6 @@ def preformat_matrix(source_file, file_format):
skipfooter=skipfooter,
engine=engine,
encoding="ISO-8859-1",
error_bad_lines=False,
)
else:
file = pd.read_csv(
Expand All @@ -164,7 +163,6 @@ def preformat_matrix(source_file, file_format):
skipfooter=skipfooter,
engine=engine,
encoding="ISO-8859-1",
error_bad_lines=False,
)

datetime_format = file_format.date.code + " " + file_format.time.code
Expand Down
4 changes: 4 additions & 0 deletions importing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import os
import shutil
import urllib
from logging import getLogger

import pandas as pd
from django.contrib.auth.decorators import permission_required
from django.http import HttpResponse, JsonResponse
from rest_framework import generics
Expand Down Expand Up @@ -58,6 +60,8 @@ class DataImportTempCreate(generics.CreateAPIView):

def perform_create(self, serializer):
file = copy.deepcopy(self.request.FILES["file"])
timezone = serializer.validated_data["station"].timezone
getLogger().warning(timezone)
matrix = preformat_matrix(file, serializer.validated_data["format"])
del file
# Set start and end date based on cleaned data from the file
Expand Down

0 comments on commit 49cd614

Please sign in to comment.