Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Send reviews

  • Loading branch information...
commit ff9ac5961f6a861e9e24dd153aa15e0ac4e54187 1 parent bfadadf
@eshurakov authored
View
8 ApplicationManager.py
@@ -117,8 +117,16 @@ def loadAndUpdateReviews(self, country = None, limit = 50):
if country is None:
self.reviewsLastDate = None
+ # i = 0
+ # total = len(appStores)
+ # progress = int((float(i) / float(total)) * 100.0)
+ # print "\r[{0}] {1}%".format('#'*(progress/10), progress)
+
for country in appStores:
self.loadAndUpdateReviews(country, limit)
+ # i += 1
+ # progress = int((float(i) / float(total)) * 100)
+ # print "\r[{0}] {1}%".format('#'*(progress/10), progress)
if self.application.reviewsLastDate is None:
self.application.reviewsLastDate = self.reviewsLastDate
View
81 manage.py
@@ -6,10 +6,23 @@
'''
import argparse
+
from storage.MongoStorage import MongoStorage
+from storage.MemoryStorage import MemoryStorage
+
from models.Subscriber import Subscriber
from models.Application import Application
+from ReviewsFetcher import ReviewsFetcher
+from ReviewsParser import ReviewsParser
+
+from ApplicationManager import ApplicationManager
+
+import smtplib
+
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+
storage = None
def getStorage():
@@ -61,6 +74,53 @@ def listSubscribers(args):
for subscriber in subscribers:
print "%s / %s" % (subscriber.email, subscriber.appId)
+def listReviews(args):
+ storage = getStorage()
+
+ reviews = storage.getReviews(appId = args.appId, limit = args.limit)
+
+ for review in reviews:
+ print "[%d stars] %s by %s on %s" % (review.rating, review.version, review.author, review.date)
+ print " (%s) %s" % (review.title, review.text)
+ print "-------------------------------------------------------------------------------------------"
+
+
+def updateReviews(args):
+ application = ApplicationManager(args.appId, getStorage())
+ application.fetcherFactory = ReviewsFetcher
+ application.parserFactory = ReviewsParser
+
+ application.loadAndUpdateReviews(country = args.country, limit = args.limit)
+
+def sendReviews(args):
+ storage = getStorage()
+ subscribers = storage.getSubscribers(appId = args.appId)
+ for subscriber in subscribers:
+ reviews = storage.getReviews(appId = args.appId, minRowId = subscriber.lastReviewId, limit = 50)
+
+ if reviews is None or len(reviews) == 0:
+ continue
+
+ fromAddr = "appstorereviews@shurakov.name"
+ toAddr = subscriber.email
+
+ msg = MIMEMultipart('alternative')
+ msg['Subject'] = "Test Subject"
+ msg['From'] = fromAddr
+ msg['To'] = toAddr
+
+ text = ''
+
+ for review in reviews:
+ text += u"[%d stars] %s by %s on %s\n%s\n%s\n\n-------\n" % (review.rating, review.version, review.author, review.date, review.title, review.text)
+
+ part1 = MIMEText(text, 'plain', 'utf-8')
+ msg.attach(part1)
+ s = smtplib.SMTP('localhost')
+ s.sendmail(fromAddr, toAddr, msg.as_string())
+ s.quit()
+
+
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@@ -83,6 +143,27 @@ def listSubscribers(args):
parser_subscribers_delete.add_argument('appId', type=int, help='application identifier')
parser_subscribers_delete.set_defaults(func=deleteSubscriber)
+
+ parser_reviews = subparsers.add_parser('reviews')
+ parser_reviews_sub = parser_reviews.add_subparsers()
+
+ parser_reviews_list = parser_reviews_sub.add_parser('list')
+ parser_reviews_list.add_argument('appId', type=int, help='application identifier')
+ parser_reviews_list.add_argument('-c', '--country', type=str, help='country', default=None)
+ parser_reviews_list.add_argument('-l', '--limit', type=int, help='limit', default=10)
+ parser_reviews_list.set_defaults(func=listReviews)
+
+ parser_reviews_update = parser_reviews_sub.add_parser('update')
+ parser_reviews_update.add_argument('appId', type=int, help='application identifier')
+ parser_reviews_update.add_argument('-c', '--country', type=str, help='country', default=None)
+ parser_reviews_update.add_argument('-l', '--limit', type=int, help='limit', default=50)
+ parser_reviews_update.set_defaults(func=updateReviews)
+
+ parser_reviews_send = parser_reviews_sub.add_parser('send')
+ #parser_reviews_send.add_argument('appId', type=int, help='application identifier', default = None, nargs='?')
+ parser_reviews_send.add_argument('appId', type=int, help='application identifier')
+ parser_reviews_send.set_defaults(func=sendReviews)
+
args = parser.parse_args()
args.func(args)
View
2  models/Review.py
@@ -6,6 +6,8 @@
class Review:
+ rowId = None
+
identifier = 0
author = None
View
9 storage/MongoStorage.py
@@ -5,6 +5,7 @@
'''
import pymongo
+from bson.objectid import ObjectId
from pymongo import Connection
from models.Review import Review
@@ -148,10 +149,11 @@ def getSubscribers(self, appId = None):
def _getReviews(self, conditions = None, limit = 0):
reviews = []
-
+
cursor = self.reviewsCollection.find(spec = conditions, limit = limit).sort([(u"date", pymongo.DESCENDING), (u"order", pymongo.DESCENDING)])
for rawReview in cursor:
review = Review()
+ review.rowId = rawReview["_id"]
review.identifier = rawReview["identifier"]
review.author = rawReview["author"]
review.appId = rawReview["appId"]
@@ -166,7 +168,7 @@ def _getReviews(self, conditions = None, limit = 0):
return reviews
- def getReviews(self, appId, limit = 0, appStoreId = None, date = None):
+ def getReviews(self, appId, limit = 0, appStoreId = None, date = None, minRowId = None):
conditions = {
"appId" : appId
}
@@ -175,6 +177,9 @@ def getReviews(self, appId, limit = 0, appStoreId = None, date = None):
if date is not None:
conditions["date"] = date
+
+ if minRowId is not None:
+ conditions["_id"] = {"$gt" : ObjectId(minRowId)}
return self._getReviews(conditions, limit)
Please sign in to comment.
Something went wrong with that request. Please try again.