set a Python program to expire after a certain number of days












0















Say I wanted to implement a 30-day trial or run a 5-day beta test. How would I go about this using Python? The idea is that the program stops working and prints a message to the user that the program has expired after said amount of time. I thought about doing it this way.



import sys
import time
start = time.time
expire = start + 2592000
while True:
Run Program
if time.time > start + expire:
sys.exit("This program has now expired")


The problem with this is that the program would have to be constantly running on the user's machine for the specified amount of time. There must be a simpler or more sensible way to go about it, like having the program check at startup if a certain number of days has been reached. Thanks in advance for your input on this.



Update



I just thought of another way of doing this. Would this work?



import datetime
import sys

start = datetime.datetime.now()
expire = start.month + 1
while True:
Run Program
if datetime.datetime.now().month == expire:
sys.exit("Your 1 month trial has expired.")









share|improve this question

























  • One way of doing this is to query your server for the expiry time and check if the current time is greater. If so, shut down the program.

    – ForceBru
    Nov 23 '18 at 9:37











  • If you want it to be secure as well I would suggest saving timestamp of when user started using program as well as his registered email or some id for his machine (so he can't just uninstall and install again for another trial) to your own server.

    – Ninad Gaikwad
    Nov 23 '18 at 9:39











  • Are you bundling your python code into a binary? It's pretty hard to achieve this is in a secure way in python. If you don't hide source code, the user (for example) can disable such a check in the source.

    – normanius
    Nov 23 '18 at 10:03
















0















Say I wanted to implement a 30-day trial or run a 5-day beta test. How would I go about this using Python? The idea is that the program stops working and prints a message to the user that the program has expired after said amount of time. I thought about doing it this way.



import sys
import time
start = time.time
expire = start + 2592000
while True:
Run Program
if time.time > start + expire:
sys.exit("This program has now expired")


The problem with this is that the program would have to be constantly running on the user's machine for the specified amount of time. There must be a simpler or more sensible way to go about it, like having the program check at startup if a certain number of days has been reached. Thanks in advance for your input on this.



Update



I just thought of another way of doing this. Would this work?



import datetime
import sys

start = datetime.datetime.now()
expire = start.month + 1
while True:
Run Program
if datetime.datetime.now().month == expire:
sys.exit("Your 1 month trial has expired.")









share|improve this question

























  • One way of doing this is to query your server for the expiry time and check if the current time is greater. If so, shut down the program.

    – ForceBru
    Nov 23 '18 at 9:37











  • If you want it to be secure as well I would suggest saving timestamp of when user started using program as well as his registered email or some id for his machine (so he can't just uninstall and install again for another trial) to your own server.

    – Ninad Gaikwad
    Nov 23 '18 at 9:39











  • Are you bundling your python code into a binary? It's pretty hard to achieve this is in a secure way in python. If you don't hide source code, the user (for example) can disable such a check in the source.

    – normanius
    Nov 23 '18 at 10:03














0












0








0


1






Say I wanted to implement a 30-day trial or run a 5-day beta test. How would I go about this using Python? The idea is that the program stops working and prints a message to the user that the program has expired after said amount of time. I thought about doing it this way.



import sys
import time
start = time.time
expire = start + 2592000
while True:
Run Program
if time.time > start + expire:
sys.exit("This program has now expired")


The problem with this is that the program would have to be constantly running on the user's machine for the specified amount of time. There must be a simpler or more sensible way to go about it, like having the program check at startup if a certain number of days has been reached. Thanks in advance for your input on this.



Update



I just thought of another way of doing this. Would this work?



import datetime
import sys

start = datetime.datetime.now()
expire = start.month + 1
while True:
Run Program
if datetime.datetime.now().month == expire:
sys.exit("Your 1 month trial has expired.")









share|improve this question
















Say I wanted to implement a 30-day trial or run a 5-day beta test. How would I go about this using Python? The idea is that the program stops working and prints a message to the user that the program has expired after said amount of time. I thought about doing it this way.



import sys
import time
start = time.time
expire = start + 2592000
while True:
Run Program
if time.time > start + expire:
sys.exit("This program has now expired")


The problem with this is that the program would have to be constantly running on the user's machine for the specified amount of time. There must be a simpler or more sensible way to go about it, like having the program check at startup if a certain number of days has been reached. Thanks in advance for your input on this.



Update



I just thought of another way of doing this. Would this work?



import datetime
import sys

start = datetime.datetime.now()
expire = start.month + 1
while True:
Run Program
if datetime.datetime.now().month == expire:
sys.exit("Your 1 month trial has expired.")






python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 9:19







Feeling Ceiling

















asked Nov 23 '18 at 9:33









Feeling CeilingFeeling Ceiling

11




11













  • One way of doing this is to query your server for the expiry time and check if the current time is greater. If so, shut down the program.

    – ForceBru
    Nov 23 '18 at 9:37











  • If you want it to be secure as well I would suggest saving timestamp of when user started using program as well as his registered email or some id for his machine (so he can't just uninstall and install again for another trial) to your own server.

    – Ninad Gaikwad
    Nov 23 '18 at 9:39











  • Are you bundling your python code into a binary? It's pretty hard to achieve this is in a secure way in python. If you don't hide source code, the user (for example) can disable such a check in the source.

    – normanius
    Nov 23 '18 at 10:03



















  • One way of doing this is to query your server for the expiry time and check if the current time is greater. If so, shut down the program.

    – ForceBru
    Nov 23 '18 at 9:37











  • If you want it to be secure as well I would suggest saving timestamp of when user started using program as well as his registered email or some id for his machine (so he can't just uninstall and install again for another trial) to your own server.

    – Ninad Gaikwad
    Nov 23 '18 at 9:39











  • Are you bundling your python code into a binary? It's pretty hard to achieve this is in a secure way in python. If you don't hide source code, the user (for example) can disable such a check in the source.

    – normanius
    Nov 23 '18 at 10:03

















One way of doing this is to query your server for the expiry time and check if the current time is greater. If so, shut down the program.

– ForceBru
Nov 23 '18 at 9:37





One way of doing this is to query your server for the expiry time and check if the current time is greater. If so, shut down the program.

– ForceBru
Nov 23 '18 at 9:37













If you want it to be secure as well I would suggest saving timestamp of when user started using program as well as his registered email or some id for his machine (so he can't just uninstall and install again for another trial) to your own server.

– Ninad Gaikwad
Nov 23 '18 at 9:39





If you want it to be secure as well I would suggest saving timestamp of when user started using program as well as his registered email or some id for his machine (so he can't just uninstall and install again for another trial) to your own server.

– Ninad Gaikwad
Nov 23 '18 at 9:39













Are you bundling your python code into a binary? It's pretty hard to achieve this is in a secure way in python. If you don't hide source code, the user (for example) can disable such a check in the source.

– normanius
Nov 23 '18 at 10:03





Are you bundling your python code into a binary? It's pretty hard to achieve this is in a secure way in python. If you don't hide source code, the user (for example) can disable such a check in the source.

– normanius
Nov 23 '18 at 10:03












1 Answer
1






active

oldest

votes


















0














If you dont care about security, create a file containing the date of the first run, for example:



import datetime
import sys

import os


first_launch_date_filepath = ".first_launch_date"


def is_program_expired():
# Query date of first lauch in given file
if os.path.exists(first_launch_date_filepath):
with open(first_launch_date_filepath, 'r') as fileRead:
time_as_str = fileRead.read()
start_date = datetime.datetime.strptime(time_as_str, "%Y_%m_%d")
# Check if current time is greater than time limit
expire_date = start_date + datetime.timedelta(days=31)
if datetime.datetime.now() > expire_date:
sys.exit("Your 1 month trial has expired.")
# Supposedly first run
else:
start_date = datetime.datetime.now()
with open(first_launch_date_filepath, 'w') as fileWrite:
fileWrite.write(start_date.strftime("%Y_%m_%d"))


if __name__ == '__main__':
is_program_expired()
# YOUR PROGRAM


Be carefull : this is very insecure, I suggest you hide that file but anyone could open this python code and figure out how to bypass this security by editing this code or the file containing the start time.



Encrypt your file, hide it, change its name.
Best way would be to use a server to store that date, upon activation, you would send the date to the server. Because this is python, any user could read, understand and modify these lines of codes to automaticaly bypass your security.






share|improve this answer


























  • To circumvent this measure the user would simply need to remove the file.

    – mhawke
    Nov 23 '18 at 10:52











  • How would this be used to specify a time limit and print an error if the user tries to run the code after the limited amount of time?

    – Feeling Ceiling
    Nov 23 '18 at 11:26











  • @FeelingCeiling compute the launch date with time in the second code block and dump it into the file, in the first code block, check in the file the date of first launch and compare it with current time.

    – Jean Bouvattier
    Nov 23 '18 at 13:02











  • My knowledge of time-based modules is quit limited so a code example would be helpful.

    – Feeling Ceiling
    Nov 24 '18 at 0:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443959%2fset-a-python-program-to-expire-after-a-certain-number-of-days%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you dont care about security, create a file containing the date of the first run, for example:



import datetime
import sys

import os


first_launch_date_filepath = ".first_launch_date"


def is_program_expired():
# Query date of first lauch in given file
if os.path.exists(first_launch_date_filepath):
with open(first_launch_date_filepath, 'r') as fileRead:
time_as_str = fileRead.read()
start_date = datetime.datetime.strptime(time_as_str, "%Y_%m_%d")
# Check if current time is greater than time limit
expire_date = start_date + datetime.timedelta(days=31)
if datetime.datetime.now() > expire_date:
sys.exit("Your 1 month trial has expired.")
# Supposedly first run
else:
start_date = datetime.datetime.now()
with open(first_launch_date_filepath, 'w') as fileWrite:
fileWrite.write(start_date.strftime("%Y_%m_%d"))


if __name__ == '__main__':
is_program_expired()
# YOUR PROGRAM


Be carefull : this is very insecure, I suggest you hide that file but anyone could open this python code and figure out how to bypass this security by editing this code or the file containing the start time.



Encrypt your file, hide it, change its name.
Best way would be to use a server to store that date, upon activation, you would send the date to the server. Because this is python, any user could read, understand and modify these lines of codes to automaticaly bypass your security.






share|improve this answer


























  • To circumvent this measure the user would simply need to remove the file.

    – mhawke
    Nov 23 '18 at 10:52











  • How would this be used to specify a time limit and print an error if the user tries to run the code after the limited amount of time?

    – Feeling Ceiling
    Nov 23 '18 at 11:26











  • @FeelingCeiling compute the launch date with time in the second code block and dump it into the file, in the first code block, check in the file the date of first launch and compare it with current time.

    – Jean Bouvattier
    Nov 23 '18 at 13:02











  • My knowledge of time-based modules is quit limited so a code example would be helpful.

    – Feeling Ceiling
    Nov 24 '18 at 0:31
















0














If you dont care about security, create a file containing the date of the first run, for example:



import datetime
import sys

import os


first_launch_date_filepath = ".first_launch_date"


def is_program_expired():
# Query date of first lauch in given file
if os.path.exists(first_launch_date_filepath):
with open(first_launch_date_filepath, 'r') as fileRead:
time_as_str = fileRead.read()
start_date = datetime.datetime.strptime(time_as_str, "%Y_%m_%d")
# Check if current time is greater than time limit
expire_date = start_date + datetime.timedelta(days=31)
if datetime.datetime.now() > expire_date:
sys.exit("Your 1 month trial has expired.")
# Supposedly first run
else:
start_date = datetime.datetime.now()
with open(first_launch_date_filepath, 'w') as fileWrite:
fileWrite.write(start_date.strftime("%Y_%m_%d"))


if __name__ == '__main__':
is_program_expired()
# YOUR PROGRAM


Be carefull : this is very insecure, I suggest you hide that file but anyone could open this python code and figure out how to bypass this security by editing this code or the file containing the start time.



Encrypt your file, hide it, change its name.
Best way would be to use a server to store that date, upon activation, you would send the date to the server. Because this is python, any user could read, understand and modify these lines of codes to automaticaly bypass your security.






share|improve this answer


























  • To circumvent this measure the user would simply need to remove the file.

    – mhawke
    Nov 23 '18 at 10:52











  • How would this be used to specify a time limit and print an error if the user tries to run the code after the limited amount of time?

    – Feeling Ceiling
    Nov 23 '18 at 11:26











  • @FeelingCeiling compute the launch date with time in the second code block and dump it into the file, in the first code block, check in the file the date of first launch and compare it with current time.

    – Jean Bouvattier
    Nov 23 '18 at 13:02











  • My knowledge of time-based modules is quit limited so a code example would be helpful.

    – Feeling Ceiling
    Nov 24 '18 at 0:31














0












0








0







If you dont care about security, create a file containing the date of the first run, for example:



import datetime
import sys

import os


first_launch_date_filepath = ".first_launch_date"


def is_program_expired():
# Query date of first lauch in given file
if os.path.exists(first_launch_date_filepath):
with open(first_launch_date_filepath, 'r') as fileRead:
time_as_str = fileRead.read()
start_date = datetime.datetime.strptime(time_as_str, "%Y_%m_%d")
# Check if current time is greater than time limit
expire_date = start_date + datetime.timedelta(days=31)
if datetime.datetime.now() > expire_date:
sys.exit("Your 1 month trial has expired.")
# Supposedly first run
else:
start_date = datetime.datetime.now()
with open(first_launch_date_filepath, 'w') as fileWrite:
fileWrite.write(start_date.strftime("%Y_%m_%d"))


if __name__ == '__main__':
is_program_expired()
# YOUR PROGRAM


Be carefull : this is very insecure, I suggest you hide that file but anyone could open this python code and figure out how to bypass this security by editing this code or the file containing the start time.



Encrypt your file, hide it, change its name.
Best way would be to use a server to store that date, upon activation, you would send the date to the server. Because this is python, any user could read, understand and modify these lines of codes to automaticaly bypass your security.






share|improve this answer















If you dont care about security, create a file containing the date of the first run, for example:



import datetime
import sys

import os


first_launch_date_filepath = ".first_launch_date"


def is_program_expired():
# Query date of first lauch in given file
if os.path.exists(first_launch_date_filepath):
with open(first_launch_date_filepath, 'r') as fileRead:
time_as_str = fileRead.read()
start_date = datetime.datetime.strptime(time_as_str, "%Y_%m_%d")
# Check if current time is greater than time limit
expire_date = start_date + datetime.timedelta(days=31)
if datetime.datetime.now() > expire_date:
sys.exit("Your 1 month trial has expired.")
# Supposedly first run
else:
start_date = datetime.datetime.now()
with open(first_launch_date_filepath, 'w') as fileWrite:
fileWrite.write(start_date.strftime("%Y_%m_%d"))


if __name__ == '__main__':
is_program_expired()
# YOUR PROGRAM


Be carefull : this is very insecure, I suggest you hide that file but anyone could open this python code and figure out how to bypass this security by editing this code or the file containing the start time.



Encrypt your file, hide it, change its name.
Best way would be to use a server to store that date, upon activation, you would send the date to the server. Because this is python, any user could read, understand and modify these lines of codes to automaticaly bypass your security.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 '18 at 9:54

























answered Nov 23 '18 at 9:49









Jean BouvattierJean Bouvattier

506




506













  • To circumvent this measure the user would simply need to remove the file.

    – mhawke
    Nov 23 '18 at 10:52











  • How would this be used to specify a time limit and print an error if the user tries to run the code after the limited amount of time?

    – Feeling Ceiling
    Nov 23 '18 at 11:26











  • @FeelingCeiling compute the launch date with time in the second code block and dump it into the file, in the first code block, check in the file the date of first launch and compare it with current time.

    – Jean Bouvattier
    Nov 23 '18 at 13:02











  • My knowledge of time-based modules is quit limited so a code example would be helpful.

    – Feeling Ceiling
    Nov 24 '18 at 0:31



















  • To circumvent this measure the user would simply need to remove the file.

    – mhawke
    Nov 23 '18 at 10:52











  • How would this be used to specify a time limit and print an error if the user tries to run the code after the limited amount of time?

    – Feeling Ceiling
    Nov 23 '18 at 11:26











  • @FeelingCeiling compute the launch date with time in the second code block and dump it into the file, in the first code block, check in the file the date of first launch and compare it with current time.

    – Jean Bouvattier
    Nov 23 '18 at 13:02











  • My knowledge of time-based modules is quit limited so a code example would be helpful.

    – Feeling Ceiling
    Nov 24 '18 at 0:31

















To circumvent this measure the user would simply need to remove the file.

– mhawke
Nov 23 '18 at 10:52





To circumvent this measure the user would simply need to remove the file.

– mhawke
Nov 23 '18 at 10:52













How would this be used to specify a time limit and print an error if the user tries to run the code after the limited amount of time?

– Feeling Ceiling
Nov 23 '18 at 11:26





How would this be used to specify a time limit and print an error if the user tries to run the code after the limited amount of time?

– Feeling Ceiling
Nov 23 '18 at 11:26













@FeelingCeiling compute the launch date with time in the second code block and dump it into the file, in the first code block, check in the file the date of first launch and compare it with current time.

– Jean Bouvattier
Nov 23 '18 at 13:02





@FeelingCeiling compute the launch date with time in the second code block and dump it into the file, in the first code block, check in the file the date of first launch and compare it with current time.

– Jean Bouvattier
Nov 23 '18 at 13:02













My knowledge of time-based modules is quit limited so a code example would be helpful.

– Feeling Ceiling
Nov 24 '18 at 0:31





My knowledge of time-based modules is quit limited so a code example would be helpful.

– Feeling Ceiling
Nov 24 '18 at 0:31




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443959%2fset-a-python-program-to-expire-after-a-certain-number-of-days%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen