Exemplo n.º 1
0
 def __init__(self, name, conn=None):
     if not conn: self._conn = dbconn()
     else: self._conn = conn
     if not name or not type(name) == type(str()):
         sys.stderr.write(
             'ERROR: must provide non-empty string as a table name!\n')
         raise Exception
     self._name = name
     self._sequence = None
Exemplo n.º 2
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()
Exemplo n.º 3
0
 def setup(self, *args, **kwargs):
     self.parms = args[0]
     self.conn = None
     self.curs = None
     self.tmyear = None
     if kwargs.get('gotodatadir', True):
         curdir = os.path.realpath(os.curdir)  # Get the canonical directory
         lastpart = curdir.split(os.sep)[-1]
         if lastpart.lower() != 'data':
             os.chdir('data')   # Fails if there is no data directory; that is intentional.
     if kwargs.get('defaultencoding', ''):
         reload(sys).setdefaultencoding(defaultencoding)
     if kwargs.get('parse', True):
         self.parms.parse()
     if kwargs.get('connect', True):
         self.conn = dbconn.dbconn(self.parms.dbhost, self.parms.dbuser, self.parms.dbpass, self.parms.dbname)
         self.curs = self.conn.cursor()
         self.curs.execute("SELECT MAX(tmyear) FROM lastfor")
         self.tmyear = self.curs.fetchone()[0]
     self.today = date.today()
     return self
Exemplo n.º 4
0
 def setup(self, *args, **kwargs):
     self.parms = args[0]
     self.conn = None
     self.curs = None
     self.tmyear = None
     #if kwargs.get('gotodatadir', True):
     #    curdir = os.path.realpath(os.curdir)  # Get the canonical directory
     #    lastpart = curdir.split(os.sep)[-1]
     #    if lastpart.lower() != 'data':
     #        os.chdir('data')   # Fails if there is no data directory; that is intentional.
     if kwargs.get('defaultencoding', ''):
         imp.reload(sys).setdefaultencoding(defaultencoding)
     if kwargs.get('parse', True):
         self.parms.parse(sections=kwargs.get('sections', None))
     if kwargs.get('connect', True):
         self.conn = dbconn.dbconn(self.parms.dbhost, self.parms.dbuser,
                                   self.parms.dbpass, self.parms.dbname)
         self.curs = self.conn.cursor()
         self.curs.execute("SELECT MAX(tmyear) FROM lastfor")
         self.tmyear = self.curs.fetchone()[0]
     self.today = date.today()
     return self
Exemplo n.º 5
0
        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)
    tax_training = curs.fetchone()[0]

    # Find all published training events in the database

    stmt = "SELECT ID, post_title, post_name from %s p INNER JOIN %s t ON p.ID = t.object_id WHERE p.post_type = 'tribe_events' AND p.post_status = 'publish' AND t.term_taxonomy_id = %%s" % (
        poststable, prefix + 'term_relationships')
Exemplo n.º 6
0
    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'])
    curs = conn.cursor()
    prefix = config['table_prefix']
    userstable = prefix + 'users'
Exemplo n.º 7
0
# Make it easy to run under TextMate
if 'TM_DIRECTORY' in os.environ:
    os.chdir(os.path.join(os.environ['TM_DIRECTORY'],'data'))

reload(sys).setdefaultencoding('utf8')

# Handle parameters
parms = tmparms.tmparms()
parms.parser.add_argument("--fromend", dest='fromend', type=int, default=7)
parms.parser.add_argument("--toend", dest='toend', type=int, default=9)
parms.parser.add_argument("--outfile1", dest='outfile1', type=argparse.FileType('w'), default='lucky7round1.html')
parms.parser.add_argument("--outfile2", dest='outfile2', type=argparse.FileType('w'), default='lucky7round2.html')

parms.parse()

conn = dbconn.dbconn(parms.dbhost, parms.dbuser, parms.dbpass, parms.dbname)
curs = conn.cursor()

today = datetime.now()
# If we're in the next year, make "today" last year.
if today.month < parms.fromend:
    try:
        today = today.replace(year=today.year-1)
    except ValueError:  # Today must be Leap Day!
        today = today.replace(year=today.year-1, day=28)
startmonth = '%d-%0.2d-01' % (today.year, parms.fromend)
endmonth = '%d-%0.2d-01' % (today.year, parms.toend)

outfile1 = parms.outfile1
outfile2 = parms.outfile2
Exemplo n.º 8
0
    parms.add_argument('--quiet', '-q', action='count')
    parms.add_argument('--verbose', '-v', action='count')
    parms.add_argument('--openhouseclubs', default='', help="")
    parms.add_argument('--outfile', default='openhouseclubs.html')
    parms.add_argument('--basedate', default='9/1')
    parms.add_argument('--finaldate', default='10/31')
    parms.add_argument('--renewto', default='3/31/2019')
    parms.add_argument('--requireopenhouse', action='store_true')

    #Do global setup
    globals.setup(parms)
    curs = globals.curs
    conn = globals.conn

    # Connect to the database
    conn = dbconn.dbconn(parms.dbhost, parms.dbuser, parms.dbpass,
                         parms.dbname)
    curs = conn.cursor()

    # Your main program begins here.

    # Figure out the full base and final dates, anchoring them in the current TM year
    basedate = tmutil.cleandate(parms.basedate)
    finaldate = tmutil.cleandate(parms.finaldate)
    # Also figure out the term end date we need, anchored to the calendar year
    renewtodate = tmutil.cleandate(parms.renewto, usetmyear=False)

    # And get the clubs on the base date
    clubs = Club.getClubsOn(curs, date=basedate)

    # And index them by name as well as number; set memdiff = 0 for each club.
    clubsByName = {}
Exemplo n.º 9
0
                       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'])
Exemplo n.º 10
0
    tmutil.gotodatadir()           # Move to the proper data directory
        
    
    # Handle parameters
    parms = tmparms.tmparms()
    parms.add_argument('--quiet', '-q', action='count')
    parms.add_argument('--verbose', '-v', action='count')
    parms.add_argument('--configfile', 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.configfile,'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:
        sys.stderr.write('No Google Analytics found in et_divi option\n')
        sys.exit(2)
    # We need to keep the length of the string unchanged
    need = len(m.group(1)) + len(m.group(2)) + len(m.group(3))
    result = re.sub(pattern, ('</script>'.ljust(need)), searchText)
    if '<script>' not in result: