Skip to content

Commit

Permalink
Fix CSV writer and monthly factory method bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
parafoxia committed Sep 27, 2021
1 parent 0775d19 commit e69fd85
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions analytix/youtube/analytics/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import csv
import datetime as dt
import json
import logging
Expand Down Expand Up @@ -509,9 +508,9 @@ def _resolve_date(original):

return self.retrieve(
_resolve_date(
since or dt.date.today() - dt.timedelta(days=last * 30)
since or dt.date.today() - dt.timedelta(days=last * 31)
),
_resolve_date(dt.date.today() - dt.timedelta(days=30)),
_resolve_date(dt.date.today() - dt.timedelta(days=31)),
dimensions=("month",),
metrics=metrics,
filters={"video": of} if of else {},
Expand Down Expand Up @@ -674,7 +673,6 @@ def to_csv(self, path, *, delimiter=","):
path += ".csv"

with open(path, mode="w", encoding="utf-8") as f:
writer = csv.writer(f, delimiter=delimiter)
writer.writerow(self.columns)
for r in self.data["rows"]:
writer.writerow(r)
f.write(f"{delimiter.join(self.columns)}\n")
for row in self.data["rows"]:
f.write(f"{delimiter.join(f'{i}' for i in row)}\n")

0 comments on commit e69fd85

Please sign in to comment.