Skip to content

Instantly share code, notes, and snippets.

@KunoiSayami
Last active December 11, 2019 17:12
Show Gist options
  • Save KunoiSayami/5628e5c1aa43aadd937d30d2778f31d2 to your computer and use it in GitHub Desktop.
Save KunoiSayami/5628e5c1aa43aadd937d30d2778f31d2 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import csv
import math
import datetime
import pytz
class _5coin_structure:
def __init__(self, row: tuple):
self.datetime = row[0]
self.category = row[1]
self.base_cost = float(row[2].replace(',', ''))
self.note = row[3]
self.currency = row[4].upper()
self.transfer_scale = float(row[5].replace(',', ''))
self.subcategory = ''
self.real_note = ''
self.get_sub_category()
self.date = ''
self.time = ''
self.init_datetime()
def get_sub_category(self) -> None:
if self.note in ('breakfast', 'dinner', 'lunch'):
self.subcategory = ''.join((self.note[0].upper(), self.note[1:]))
self.real_note = ''
else:
self.real_note = self.note
self.subcategory = self.note
if self.subcategory == '':
self.subcategory = 'General'
def init_datetime(self) -> None:
d = datetime.datetime.fromisoformat(self.datetime[:-1])
d.replace(tzinfo=pytz.utc)
d = d + datetime.timedelta(hours=8)
print(d.isoformat())
#d.fromisoformat(self.datetime[:-1])
#d = pytz.utc.localize(d)
#d = pytz.utc.localize(local.localize(d))
self.date, self.time = f"{d.month}/{d.day}/{d.year - 2000} {d.hour}:{d.minute}".split()
#self.date, self.time = d.strftime("%Y/%m/%d %H:%M:%S").split()
#self.time = ':'.join(self.time.split(':')[:2])
def get_cost(self) -> float:
if self.transfer_scale == 1:
return self.base_cost
return math.ceil(self.base_cost * self.transfer_scale)
def get_list(self) -> list:
return [self.currency, '', 'Expense', self.category, self.subcategory, -self.get_cost(), '', '', self.note, '', self.date, self.time, 'Life', '', '', '']
l = []
with open('5coins_export.csv', encoding='utf8') as fin:
csv_reader = csv.reader(fin, delimiter=',')
for _row in csv_reader:
print(_row)
l.append(_5coin_structure(_row))
with open('ex.csv', 'w', encoding='utf8') as fout:
fieldnames = ['Account', 'Currency', 'Type', 'Main' 'Category', 'Subcategory', 'Price',
'Fee', 'Bonus', 'Name', 'Store', 'Date', 'Time', 'Project', 'Note', 'Tags', 'Target']
csv_writter = csv.writer(fout, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
csv_writter.writerow(fieldnames)
for x in l:
csv_writter.writerow(x.get_list())
with open('ex.csv', encoding='utf8') as fin, open('exp.csv', 'w', encoding='utf8') as fout:
s = 'setsaeteatastsatsa'
while s != '':
s = fin.readline()
if s == '\n': continue
fout.write(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment