LoginSignup
2
2

More than 1 year has passed since last update.

一定期間が過ぎたら使用できなくするコードの作成

Posted at

背景

pyinstallerとかでexe化してお試し版を配布する際に、使用期限を付けたいときのコードです。自分で作ったexeが勝手に独り歩きしてあちこちで配布されないために…。

コード説明

1:今日の日付を入手
2:使用制限"limitdate"を記載して、日付方式に変更。
3:日付を比較して、使用期限を過ぎていないようであれば、何か他の操作に移る。
 (ここではOKがプリントされます)

limit.py
from datetime import datetime

today = datetime.now()

def LIMIT():
  limitdate= str("2021/05/19")
  limitdate = datetime.strptime(limitdate,"%Y/%m/%d") 
  if limitdate >= today:
    print("OK")
  else: 
    sys.exit()

LIMIT()
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2