Package: dhutil
Python utils for DataHack.~dhutilmailconfirm_statEmailsstasonDataHack2019registration:432totalusersinthesystem.415usersgotaconfirmationemail.Contents1Installation2Configure2.1MongoDB2.2Email2.3Mailchimp2.4Google Drive3Use3.1mongo3.1.1user_stats3.2mail3.2.1confirm_stat3.2.2confirm_send3.3mailchimp3.3.1lists3.3.2sync_reg3.4drive4Contributing4.1Installing for development4.2Running the tests4.3Adding documentation5Credits1InstallationInstalldhutilwith:pipinstalldhutil2Configuredhutiluses configuration files located at a folder named.datahackin your home folder (i.e.~/.datahack). Create this folder and populate it with the desired files.2.1MongoDBTo enable MongoDB access, put amongodb_credentials.jsonfile in the~/.datahackfolder with the following properties:{"host":"ds162883.mlab.com","port":"26552","usr":"some_user","pwd":"pAsswOrd","authSource":"db_name","srv":true,"db":"test"}These are example values; you need to use the database-specific host and port supplied bymlab, a username and password of a user created inside thatmlabdatabase (not the username and password used to log intomlab!), and the name of that database as theauthSourceparameter.2.2EmailTo enable email access, put anemail_credentials.jsonfile in the~/.datahackfolder with the following properties:{"host":"smtp.zoho.com","port":"587","usr":"zoho_username","pwd":"wOwPassWord"}These are example values; host and port are correct (for the ZohoMail SMTP server), but you need to put the username and password of the ZohoMail account you want to use to send emails, or put in the details of another SMTP server.2.3MailchimpTo enable mail access, put anmailchimp_credentials.jsonfile in the~/.datahackfolder with the following properties:{"username":"mchimp_uname","secret_key":"o8347583489t03894tr29","registrants_list_id":"9uy24hw9fue","accepted_list_id":"208dj2dj2"}These are example values; use the desired username and issue an API key for that user. Also take the actual ids of the registrants and accepted MailChimp lists.2.4Google DriveTo enable Google Drive access, follow theinstructions hereto create a service account with Google Drive access, and create a json key file for it.Place this file in the~/.datahackfolder, and rename it togoogle_drive_service_account_key.json.Don’t forget to follow all the above instructions, including sharing your spreadsheet with an email you have in yourjson_key['client_email'](Otherwise you’ll get a SpreadsheetNotFound exception when trying to open it).Additionally, creategoogle_drive_cfg.jsonfile at the~/.datahackfolder, and populate it with the key of the users spreadsheet, and the name of the specific worksheet within it in which users are listed:{"users_spreadsheet_key":"08924ufo8u2ndfuqihdo7g23dfh","users_worksheet_name":"Users"}3UseWhen you installdhutila command (of the corresponding name) giving access to its CLI is installed on your system. Typedhutilin terminal to get a list of the available sub-commands:~dhutilUsage:dhutil[OPTIONS]COMMAND[ARGS]...Acommand-lineinterfacefordhutil.Options:--helpShowthismessageandexit.Commands:mailEmailrelatedcommands.mailchimpMailChimprelatedcommands.mongoMongoDBrelatedcommands.3.1mongoSome MOngoDB-related utilities. Typedhutil mongoin terminal to get a list of the available MOngoDB-related commands:~dhutilmongoUsage:dhutilmongo[OPTIONS]COMMAND[ARGS]...MongoDBrelatedcommands.Options:--helpShowthismessageandexit.Commands:user_statsPrintuserstats.3.1.1user_statsPrints statistics on users in the database.3.2mailSome email-related utilities. Typedhutil mailin terminal to get a list of the available email-related commands:~dhutilmailUsage:dhutilmail[OPTIONS]COMMAND[ARGS]...Emailrelatedcommands.Options:--helpShowthismessageandexit.Commands:confirm_sendSendconfirmationemails.confirm_statStatusofconfirmationemails.3.2.1confirm_statThedhutil mail confirm_statterminal command will print to termintal how many users gotconfirmationemails (not acceptance emails):~dhutilmailconfirm_statEmailsstasonDataHack2017registration:432totalusersinthesystem.415usersgotaconfirmationemail.3.2.2confirm_sendThedhutil mail confirm_sendterminal command will first print to terminal confirmation emails stats, and then will sendconfirmationemails (not acceptance emails) to any registered user who has not gotten one yet, and will mark them as such. Emails are sent with 50 recipents per-email (so not to use up the daily email quota), which are all BCCed so they can’t see who else is CCed:~dhutilmailconfirm_sendEmailsstasonDataHack2017registration:250totalusersinthesystem.247usersgotaconfirmationemail.Sendingconfirmationemailstoallnon-confirmedusers.Sendingaconfirmationemailtothefollowingaddresses:['test.tesi@test.com','second.example@gmail.com','third@gmail.com']EmailsentsuccessfullyUsersmarkedasconfirmedonMongoDB==========1confirmationemailsweresentto3users.3.3mailchimp3.3.1listsLists all the mailing lists on the connected account.3.3.2sync_regSync the MailChimp registrants list with the registration system’s DB, adding any missing user. Prints a progress bar while doing so.3.4drivesync_acceptedSync Google Drive acceptance status to MongoDB.4ContributingPackage author and current maintainer is Shay Palachy (shay.palachy@gmail.com); You are more than welcome to approach him for help. Contributions are very welcomed.4.1Installing for developmentClone:gitclonegit@github.com:DataHackIL/dhutil.gitInstall in development mode with test dependencies:cddhutilpipinstall-e".[test]"4.2Running the testsTo run the tests (none at the moment), usepython-mpytest--cov=dhutil4.3Adding documentationThis project is documented using thenumpy docstring conventions, which were chosen as they are perhaps the most widely-spread conventions that are both supported by common tools such as Sphinx and result in human-readable docstrings (in my personal opinion, of course). When documenting code you add to this project, please followthese conventions.5CreditsCreated by Shay Palachy  (shay.palachy@gmail.com).