copy_and_import.py 701 B

123456789101112131415161718192021222324252627
  1. import calendar
  2. import datetime
  3. import typer
  4. filename = "test.csv"
  5. archive_folder = "Archiv"
  6. def main():
  7. today = datetime.datetime.now().date()
  8. end_of_month = last_day_of_month(today)
  9. last_month = today - datetime.timedelta(days=30)
  10. end_of_last_month = last_day_of_month(last_month)
  11. if today == end_of_month:
  12. archive_filename = archive_folder + "\\" + filename[:-4] + "_" + today.isoformat() + filename[-4:]
  13. def last_day_of_month(any_date: datetime.date) -> datetime.date:
  14. end_of_month = calendar.monthrange(any_date.year, any_date.month)[2]
  15. return datetime.date(any_date.year, any_date.month, end_of_month)
  16. if __name__ == "__main__":
  17. typer.run(main)