I have a python script for checking re-investment settings on a popular bitcoin mining site and I would like to use Pyinstaller to create a windows .exe file to distribute. However, in the payload section where I pass an email and password, the user would not be able to edit that. So I need to be able to generate the .exe and a config file where the user can edit their email and password information.
I am using requests (session) and the example payload is like this:
payload = {
'action': 'dashboard.php',
'email': 'user@email.com',
'password': 'abc123-pass'
}
I need to change these to variables and have them read from a config file when the exe is executed.
simply use configparser or (ConfigParser for Python2.7) to access configuration files. Then you can create a configuration file like:
# This is the configuration file for my script for user X
[DEFAULT]
action = dashboard.php
email = user@email.com
password = abc123-pass`
In your script
import configparser
my_config_parser = configparser.SafeConfigParser()
my_config_parser.read('name of your configuration file')
payload = {
'action': my_config_parser.get('DEFAULT','action'),
'email': my_config_parser.get('DEFAULT','email'),
'password': my_config_parser.get('DEFAULT','password')
}
The configuration file you need to send with the exefied script.
You can also pass options --exclude-module settings add-data settings.py;.
to PyInstaller. That way settings.py will end up in the directory with compiled application and can be imported in usual way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.