Skip to content

Instantly share code, notes, and snippets.

@socalal
Last active April 18, 2016 22:20
Show Gist options
  • Save socalal/55d43f63f1eb18175f00f9507e053c14 to your computer and use it in GitHub Desktop.
Save socalal/55d43f63f1eb18175f00f9507e053c14 to your computer and use it in GitHub Desktop.
Duplicate website - socalal
#!/usr/bin/python
# Created by Alan M. Orther - alan.orther@gmail.com
# This script is used to duplicate a Wordpress website and DB.
import os
import random
# Variables
website_url = ""
website_url_dir = ""
city_name = ""
state_abb = ""
db_name = ""
db_user = ""
db_pass = ""
def website_url_function():
# Get the domain name and create the domain directory name.
global website_url, website_url_dir
user_input = raw_input("\nPlease copy and paste the new domain name:"
" ").lower()
website_url = user_input.strip()
website_url_dir = website_url.replace('.', '')
def city():
# Get the name of the city for this jobs website and remove spaces.
global city_name
user_input = raw_input("What city is this site for? ").lower()
city_input = user_input.strip()
city_name = city_input.replace(" ", "")
def state():
# Get the name of the state for this jobs website and remove spaces.
global state_abb
user_input = raw_input("What is the state abbreviation for the city? Ex: "
"California = CA : ").lower()
state_input = user_input.strip()
state_abb = state_input.replace(" ", "")
# Confirm the state abbreviation is 2 characters or quit.
if len(state_abb) != 2:
print "\nThe state abbreviation needs to be 2 characters.\n"
state()
def db_info():
global db_name, db_user, db_pass, website_url_dir, state_abb, city_name
# Create the DB, DB user (max 16 char), and DB password.
# DB name is wpjob + the domain name without the "." + state abbreviation.
db_name = "wpjob" + website_url_dir + state_abb
# Create DB user. It is the wpjob + first 5 of the city name + the state
# abbreviation + random 2 digit number.
db_user = "wpjob" + str(random.randint(10, 99)) + city_name[:6] + state_abb
# Create the DB password. It is wppass + first 2 of the city name + the
# state abbreviation + random 2 digit number.
db_pass = "wppass" + str(random.randint(10, 99)) + city_name[:2] + state_abb
website_url_function()
city()
state()
db_info()
print "\nWebsite URL = " + website_url
print "Website directory = /var/www/" + website_url_dir
print "DB name = " + db_name
print "DB user = " + db_user
print "DB password = " + db_pass + "\n"
# Create webpage directory in /var/www/ if it doesn't already exist.
# Create the directory path and expand it in the shell.
webpage_directory_string = "/var/www/%s/" % website_url_dir
webpage_directory = os.path.expanduser(webpage_directory_string)
# Check if the directory exists. If it exists, warn and quit. If not, create it.
# Check for directory and exit script if it exists.
if os.path.exists(webpage_directory):
print "\nThis website directory already exists. Exiting program.\n"
quit()
# Check for directory and create it is it doesn't.
if not os.path.exists(webpage_directory):
os.makedirs(webpage_directory)
# Create or open and append to webinfo.log file. Adds all names and credentials.
log = open(webpage_directory + 'webpageinfo.log', 'a+')
write = "\nWebsite URL: %s\n" % website_url
log.write(write)
write = "Website directory: %s\n" % webpage_directory_string
log.write(write)
write = "City: %s\n" % city_name
log.write(write)
write = "State: %s\n" % state_abb
log.write(write)
write = "DB Name: %s\n" % db_name
log.write(write)
write = "DB Username: %s\n" % db_user
log.write(write)
write = "DB Password: %s\n" % db_pass
log.write(write)
write = "\n"
log.write(write)
log.close()
# Ask user to input the root database password.
password = raw_input("Please type the DB root password and hit Enter: ")
print "The MySQL root password is: %s" % password
# Edit the files
# s = open("mount.txt").read()
# s = s.replace('mickey', 'minnie')
# f = open("mount.txt", 'w')
# f.write(s)
# f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment