Example #1
0
    def __init__(self, parms):
        config = tmutil.parseWPConfig(
            open(os.path.join(parms.wpdir, 'wp-config.php'), 'r'))
        if parms.uselocal:
            config['DB_HOST'] = 'localhost'

        # Connect to the WP Database
        self.conn = dbconn.dbconn(config['DB_HOST'], config['DB_USER'],
                                  config['DB_PASSWORD'], config['DB_NAME'])
        self.curs = self.conn.cursor()
        self.prefix = config['table_prefix']
        self.poststable = self.prefix + 'posts'
        self.optionstable = self.prefix + 'options'
        self.postmeta = self.prefix + 'postmeta'
        self.venue_numbers = set()
Example #2
0
    parms.end = parms.now
    if parms.now.month >= 5 and parms.now.month <= 9:
        parms.start = parms.start.replace(month=6, day=1)
        parms.end = parms.end.replace(month=9, day=30)
    else:
        parms.start = parms.start.replace(month=11, day=1)
        parms.end = parms.end.replace(month=3, day=31)
        if parms.now.month >= 10:
            parms.end = parms.end.replace(year=parms.end.year + 1)
        else:
            parms.start = parms.start.replace(year=parms.start.year - 1)
    # But we don't care about past trainings, set start to today
    parms.start = parms.now.replace(hour=0, minute=0, second=0)

    # Parse the configuration file
    config = tmutil.parseWPConfig(
        open(os.path.join(parms.wpdir, 'wp-config.php'), 'r'))
    if parms.uselocal:
        config['DB_HOST'] = 'localhost'

    # Connect to the WP database
    conn = dbconn.dbconn(config['DB_HOST'], config['DB_USER'],
                         config['DB_PASSWORD'], config['DB_NAME'])
    curs = conn.cursor()
    prefix = config['table_prefix']
    poststable = prefix + 'posts'
    optionstable = prefix + 'options'

    # Find the taxonomy value for 'training'
    stmt = "SELECT term_id FROM %s WHERE slug = 'training'" % (prefix +
                                                               'terms')
    curs.execute(stmt)
Example #3
0
    # Establish parameters
    parms = tmparms.tmparms()
    # Add other parameters here
    parms.add_argument('--configfile', type=str, default='/var/www/html/wp-config.php')

    # Do global setup
    globals.setup(parms,connect=False)

    # Parse the current user's .my.cnf file; this must have the username and password in the [client] section.
    msconfig = configparser.ConfigParser()
    msconfig.read(os.path.expanduser("~/.my.cnf"))
    username = msconfig.get("client", "user")
    password = msconfig.get("client", "password")

    # Parse the WordPress configuration file
    config = tmutil.parseWPConfig(open(parms.configfile,'r'))

    # Connect as the active user, who needs full authority over WordPress
    conn = dbconn.dbconn('localhost', username, password, '')
    curs = conn.cursor()

    # Make sure the WP user can access the database
    curs.execute("CREATE USER IF NOT EXISTS '%s'@'localhost' IDENTIFIED BY '%s'" % (config['DB_USER'], config['DB_PASSWORD']))
    ("GRANT ALL PRIVILEGES ON '%s'.'*' TO '%s'@'localhost'" % (config['DB_NAME'], config['DB_USER']))
    curs.execute("FLUSH PRIVILEGES")

    conn.close()


    # Connect to the WP database     
    conn = dbconn.dbconn(config['DB_HOST'], config['DB_USER'], config['DB_PASSWORD'], config['DB_NAME'])
Example #4
0
### Insert classes and functions here.  The main program begins in the "if" statement below.

if __name__ == "__main__":

    import tmparms

    # Handle parameters
    parms = tmparms.tmparms()
    parms.add_argument('--quiet', '-q', action='count')
    parms.add_argument('--verbose', '-v', action='count')
    parms.add_argument('--wpconfigfile', type=str, default='/dev/null')
    # Add other parameters here
    parms.parse()

    # Parse the WP Configuration file to find the database
    config = tmutil.parseWPConfig(open(parms.wpconfigfile, 'r'))
    # Connect to the database
    conn = dbconn.dbconn(config['DB_HOST'], config['DB_USER'],
                         config['DB_PASSWORD'], config['DB_NAME'])
    curs = conn.cursor()
    prefix = config['table_prefix']
    optiontable = prefix + 'options'
    curs.execute("SELECT option_value FROM %s WHERE option_name = 'et_divi'" %
                 optiontable)
    searchText = curs.fetchone()[0]

    pattern = re.compile(
        r"(</script>|^)(\s*)(<script>.*?GoogleAnalyticsObject.*?</script>)",
        re.I | re.M | re.S)
    m = re.search(pattern, searchText)
    if not m: