Commit d53c3e9d authored by Anastasia Galkin's avatar Anastasia Galkin
Browse files

queries corrected

parent 134a7c03
settings*
*.log
./idea
robo*
#!/usr/bin/python
import sys
import time
import MySQLdb
from settings import *
log_name = '' + time.strftime("%Y%m%d_%H%M%S") + '_wordpress_stats.log'
......@@ -12,28 +14,31 @@ file = open(log_name, "w")
for i, wp in WORDPRESS_DATABASES.items():
file.write("Wordpress: '{0}' ".format(i) + '\n')
nonews = True
db = MySQLdb.connect(wp['HOST'],wp['USER'],wp['PASSWORD'],wp['DATABASE'])
cursor = db.cursor()
# users, posts, pages
for j, stats in WORDPRESS_STATS.items():
cursor.execute(stats['count'])
count = cursor.fetchone()
if count > 0:
if int(count[0]) > 0:
nonews = False
file.write("{0} new {1}\n".format(''.join(map(str,count)), j) )
file.write(stats['header'] + "\n")
cursor.execute(stats['query'])
for row in cursor:
file.write(' | '.join(map(str, row)) + '\n')
file.write(' \n')
if nonews:
file.write(' Nothing new here.')
file.write(' \n')
db.close()
file.close()
\ No newline at end of file
file.close()
# DATABASES = {
# 'default': {
# 'NAME': '',
# 'USER': '',
# 'PASSWORD': '',
# 'HOST': '',
# 'PORT': '',
# 'DATABASE: '',
# }
# }
WORDPRESS_DATABASES = {
'default': {
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
'DATABASE': '',
}
}
WORDPRESS_STATS = {
'users': {
'count': "SELECT COUNT(*) FROM wp_users WHERE user_registered >= NOW() - INTERVAL 1 DAY",
'count': "SELECT COUNT(*) FROM `wp_users` WHERE `user_registered` >= NOW() - INTERVAL 1 DAY",
'header': 'ID | user_login | display_name | user_registered',
'query': "SELECT ID, user_login, display_name, user_registered FROM wp_users WHERE user_registered >= NOW() - INTERVAL 1 DAY",
'query': "SELECT `ID`, `user_login`, `display_name`, `user_registered` FROM `wp_users` WHERE `user_registered` >= NOW() - INTERVAL 1 DAY",
},
'posts': {
'count': "SELECT COUNT(*) FROM wp_posts WHERE post_type LIKE post AND post_modified >= NOW() - INTERVAL 1 DAY",
'count': "SELECT COUNT(*) FROM `wp_posts` WHERE `post_type` LIKE \'post\' AND `post_modified` >= NOW() - INTERVAL 1 DAY",
'header': 'ID | post_author | post_modified | post_title',
'query': "SELECT ID, post_author, post_modified, post_title FROM wp_posts WHERE post_type LIKE post AND post_modified >= NOW() - INTERVAL 1 DAY",
'query': "SELECT `ID`, `post_author`, `post_modified`, `post_title` FROM `wp_posts` WHERE `post_type` LIKE \'post\' AND `post_modified` >= NOW() - INTERVAL 1 DAY",
},
'pages': {
'count': "SELECT COUNT(*) FROM wp_posts WHERE post_type LIKE page AND post_modified >= NOW() - INTERVAL 1 DAY",
'count': "SELECT COUNT(*) FROM `wp_posts` WHERE `post_type` LIKE \'page\' AND `post_modified` >= NOW() - INTERVAL 1 DAY",
'header': 'ID | post_author | post_modified | post_title',
'query': 'SELECT ID, post_author, post_modified, post_title FROM wp_posts WHERE post_type LIKE page AND post_modified >= NOW() - INTERVAL 1 DAY',
'query': 'SELECT `ID`, `post_author`, `post_modified`, `post_title` FROM `wp_posts` WHERE `post_type` LIKE \'page\' AND `post_modified` >= NOW() - INTERVAL 1 DAY',
},
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment