def post(self):
        logging.info('tasks/harvest_so')

        # get the gde Account entity
        safe_key = self.request.get('key')
        gde = ndb.Key(urlsafe=safe_key).get()
        logging.info(gde.gplus_id)
        logging.info(gde)

        # harvesting interval set to weekly with a page size of 100
        to_date = datetime.strptime(self.request.get('to'), "%Y-%m-%d").date()
        from_date = datetime.strptime(
            self.request.get('from'), "%Y-%m-%d").date()

        logging.info("harvesting from {} to {}".format(from_date, to_date))

        # populate product groups and tags associated with the Expert
        # multiple product groups is not uncommon and even more so
        # with the polymer harvesting experiment

        # changed the approach above so that all product group questions
        # are recorded independant of the Expert product group affiliation.
        pg_tags = {}
        product_groups = ProductGroup.query().fetch(100)
        for pg in product_groups:
            product_group = pg
            # not sure why I am dealing with unicode here :(
            so_tags = [x.encode('UTF8') for x in product_group.so_tags]
            pg_tags[product_group.id] = {}
            for tag in so_tags:
                pg_tags[product_group.id][tag] = 0

        logging.info(pg_tags)

        query = "/answers?key=" + SO_KEY + \
            "&page=1&pagesize=100&site=stackoverflow&order=desc&sort=creation&filter=default"

        query = query + \
            "&fromdate={}&todate={}".format(
                from_date.strftime('%s'), to_date.strftime('%s'))

        url = SO_ROOT + \
            "/users/{}".format(gde.so_id) + query

        logging.info(url)

        req = Request(url)
        res = urlopen(req).read()
        answers = json.loads(res)["items"]
        logging.info("Number of answers posted this period %s" % len(answers))

        # identify if the answers are specific to tags of interest
        for answer in answers:
            self.add_answer_to_tag_count(pg_tags, answer["question_id"])

        logging.info(pg_tags)

        # create Activity Records for product group that have some answers
        # for product_group in pg_tags:
        for pg in product_groups:
            product_group = pg
            count = 0
            for pg_tag in pg_tags[product_group.id]:
                count += pg_tags[product_group.id][pg_tag]
            if count != 0:
                logging.info(
                    "create ar for {} with {} answers".format(product_group.description, count))

                # UPGRADE LINK TO THE SET OF ANSWERS THAT WHERE RECORDED
                link = "http://stackoverflow.com/search?q=user:" + \
                    gde.so_id + urllib.quote_plus(" ")
                link_tags = ""

                for pg_tag in pg_tags[product_group.id]:
                    if link_tags != "":
                        link_tags += urllib.quote_plus(" OR ")
                    link_tags += "[" + pg_tag + "]"

                link += link_tags

                link_date = urllib.quote_plus(" is:answer created:") + \
                    str(to_date.year) + '-' + str(from_date.month)

                link = link + link_date

                to_date_human = to_date - timedelta(1)

                title = "SO HARVEST - {} - from {} to {}".format(
                    product_group.tag, str(from_date), str(to_date_human))

                activities = ActivityRecord.query(ActivityRecord.gplus_id == gde.gplus_id,
                                                  ActivityRecord.metadata.type == '#stackOverflow',
                                                  ActivityRecord.post_date == str(
                                                      to_date),
                                                  ActivityRecord.activity_title == title)

                if activities.count(20) == 0:
                    logging.info("create activity record")
                    activity_record = ActivityRecord(gplus_id=gde.gplus_id,
                                                     post_date=str(to_date),
                                                     activity_types=[
                                                         "#forumpost"],
                                                     product_groups=[
                                                         product_group.tag],
                                                     activity_link=link,
                                                     activity_title=title,
                                                     plus_oners=0,
                                                     resharers=0,
                                                     comments=0,
                                                     deleted=False)
                    activity_record.metadata.insert(0, ActivityMetaData())
                    meta = activity_record.metadata[0]
                    meta.type = '#stackOverflow'
                    meta.activity_group = '#forumpost'
                    meta.link = activity_record.activity_link
                    meta.impact = count
                    activity_record.put()
                else:
                    logging.info("ActivityRecord Exist Not Overwritting")
.
dataset/ETHPy150Open GoogleDeveloperExperts/experts-app-backend/services/so_tasks.py/TaskHarvestSO.post