def retornarCampaignsBDxEmail(user_email): campaignsBD = configTables.session.query(configTables.Campaign).filter_by(email=user_email).all() campaigns = [] for cBD in campaignsBD: c = Campaign(cBD.id, cBD.email, cBD.hashtags, cBD.mentions, cBD.startDate, cBD.finDate) campaigns.append(c) return campaigns
def retornarCampaignBD(idC): campaignespecifica = configTables.session.query(configTables.Campaign).get(idC) #Con la campaignespecifica de arriba accedemos a los atributos así: (ya que es el objeto Campaign de configTables.py) #print(campaignespecifica.id, campaignespecifica.email, campaignespecifica.hashtags, campaignespecifica.mentions, campaignespecifica.startDate, campaignespecifica.finDate) #Devuelve esto: 2 [email protected] #federicio-#federicio2 @hola-@hola2 2018-11-28 2018-12-02 --> con print envés de return se ve. if type(campaignespecifica) == NoneType: return [] return Campaign(campaignespecifica.id, campaignespecifica.email, campaignespecifica.hashtags, campaignespecifica.mentions, campaignespecifica.startDate, campaignespecifica.finDate)
def insertCampaign(self, userInputs): #Con los nombres de los campos correspondientes a los del json que nos llegan armamos un objeto campaña. #Pero antes de esto como fields["hashtags"] y fields["mentions"] son LISTAS, tenemos que pasarlas a un string para poder añadirlo a la BD como un varchar: stringHashtag = self.listaAString(userInputs["hashtags"]) # #donaldTrump-#G20 stringMention = self.listaAString(userInputs["mentions"]) # @donaldTrump-@miauricioOK ObjetoCampaign = Campaign(1, userInputs["email"], stringHashtag, stringMention, userInputs["startDate"], userInputs["endDate"]) #Llamamos a un metodo de Connector para agregar la campaña a la BD junto con las mentions y los hashtags: return Connector.insertarCampaignBD(ObjetoCampaign)
class test_manager_base(unittest.TestCase): campaignCreationData = {'email':'*****@*****.**', 'hashtags':['#JOKER','#SMASH'], 'mentions':['@Sora_Sakurai'], 'startDate':"31 12 2050 23:20:00", 'endDate':"01 01 2051 00:30:00"} campaignCreationDataError = {'hashtags':'#JOKER-#smash', 'mentions':'@Sora_Sakurai', 'startDate':"31 12 2050 23:20:00", 'endDate':"01 01 2051 00:30:00"} campaignDeleteByIDCData = {'idC':1} campaignDeleteByEmailData = {'email':"*****@*****.**"} campaignDeleteDataError = {'hype':"JOKER_IN_SMASH"} campaignPatchHashtagsData = {'columnaAModif':'hashtags', 'campoColumna':['#qatherine','#katherine','#catherine']} campaignPatchMentionsData = {'columnaAModif':'mentions', 'campoColumna':['@atlususa','@stud_zero']} campaignPatchErrorData = {'campoColumna':['@atlususa','@stud_zero']} initialCampaigns = [Campaign(1, "*****@*****.**", '#NothingBreaksLikeAHeart', "", "31 12 2050 23:20:00", "01 01 2051 00:30:00"), Campaign(2, "*****@*****.**", "", '@POTUS', "31 12 2050 23:20:00", "01 01 2051 00:30:00"), Campaign(3, "*****@*****.**", '#nintendo-#SMASH', '@Sora_Sakurai-@nintendo', "31 12 2050 23:20:00", "01 01 2051 00:30:00")] def setUp(self): pass def tearDown(self): pass
def api_fetcher(): if 'Content-Type' in request.headers.keys(): if request.headers['Content-Type'] == 'application/json': cJson = json.loads(request.json) if check(cJson): campaign = Campaign(cJson["id"], cJson["email"], cJson["hashtags"], cJson["mentions"], cJson["startDate"], cJson["finDate"]) fetcher.fetchTweets(campaign) return Response(status=200) else: return Response(status=400) else: return Response(400) else: return Response(status=400)
def _dbCampaignToCampaign(self, dbC): return Campaign(dbC.id, dbC.email, dbC.hashtags, dbC.mentions, dbC.startDate, dbC.finDate)
class test_reporter_base(unittest.TestCase): initialCampaigns = [ Campaign(1, "*****@*****.**", '#NothingBreaksLikeAHeart', "", "25 02 2018 18:00:00", "25 02 2018 18:30:00"), Campaign(2, "*****@*****.**", "", '@atlususa', "25 02 2018 18:00:00", "25 02 2018 18:30:00"), Campaign(3, "*****@*****.**", '#nintendo-#SMASH', '@Sora_Sakurai-@nintendo', "25 02 2018 18:00:00", "25 02 2018 18:30:00") ] initialTweets = [{ 'ID': '1000', 'userName': '******', 'userid': '10001', 'hashtags': '#NothingBreaksLikeAHeart', 'mentions': '@mileycyrus', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 1 }, { 'ID': '1001', 'userName': '******', 'userid': '10001', 'hashtags': '#NothingBreaksLikeAHeart-#feminism', 'mentions': '', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 1 }, { 'ID': '1002', 'userName': '******', 'userid': '10002', 'hashtags': '#NothingBreaksLikeAHeart-#shit', 'mentions': '@mileycyrus', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 1 }, { 'ID': '1003', 'userName': '******', 'userid': '10003', 'hashtags': '#NothingBreaksLikeAHeart-#ThankYouNext', 'mentions': '@mileycyrus-@arianagrande', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 1 }, { 'ID': '1004', 'userName': '******', 'userid': '10001', 'hashtags': '#feminism-#catherine', 'mentions': '@atlususa', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 2 }, { 'ID': '1005', 'userName': '******', 'userid': '10004', 'hashtags': '#HYPE-#SMASH-#JOKER', 'mentions': '@atlususa', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 2 }, { 'ID': '1006', 'userName': '******', 'userid': '10004', 'hashtags': '#catherine-#katherine-#qatherine-#HYPE-#SMASH', 'mentions': '@atlususa', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 2 }, { 'ID': '2000', 'userName': '******', 'userid': '10004', 'hashtags': '#HYPE-#SMASH-#JOKER', 'mentions': '@atlususa', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2001', 'userName': '******', 'userid': '10004', 'hashtags': '#catherine-#katherine-#qatherine-#HYPE-#SMASH', 'mentions': '@atlususa', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2002', 'userName': '******', 'userid': '10005', 'hashtags': '#SMASH-#nintendo-#waluigi', 'mentions': '', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2003', 'userName': '******', 'userid': '10005', 'hashtags': '#waluigi', 'mentions': '@Sora_Sakurai', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2004', 'userName': '******', 'userid': '10005', 'hashtags': '#PleaseGoToSleep', 'mentions': '@Sora_Sakurai', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2005', 'userName': '******', 'userid': '10004', 'hashtags': '#PleaseGoToSleep-#HYPE', 'mentions': '@Sora_Sakurai', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2006', 'userName': '******', 'userid': '10005', 'hashtags': '#waluigi-#SMASH-#nintendo', 'mentions': '@Sora_Sakurai', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2007', 'userName': '******', 'userid': '10005', 'hashtags': '#waluigi-#CRY', 'mentions': '@Sora_Sakurai', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }, { 'ID': '2008', 'userName': '******', 'userid': '10005', 'hashtags': '#waluigi-#SMASH-#NEVERFORGET', 'mentions': '@nintendo', 'date': 'Sun Feb 25 18:11:01 +0000 2018', 'idCampaign': 3 }] def setUp(self): pass def tearDown(self): pass
def setUp(self): self.lastId = "967824267948770000" self.tweetsId = [ "967824267948773377", "967824267948773378", "123824267948773377", "123824267948773378" ] self.campaign = Campaign("idC", "emailDueño", ["#mars"], ["@mars"], "06 12 2018 23:20:00", "07 12 2018 00:00:30") self.hastag = { "statuses": [{ "created_at": "Sun Feb 25 18:11:01 +0000 2018", "id_str": "967824267948773377", "text": "", "entities": { "hashtags": ["mars"], "user_mentions": [], }, "user": { "id_str": "11348282", "name": "NASA" } }, { "created_at": "Sun Feb 25 18:11:01 +0000 2018", "id_str": "967824267948773378", "text": "", "entities": { "hashtags": ["mars"], "user_mentions": [], }, "user": { "id_str": "11348282", "name": "NASA" } }] } self.mention = { "statuses": [{ "created_at": "Sun Feb 25 18:11:01 +0000 2018", "id_str": "123824267948773377", "text": "", "entities": { "hashtags": [], "user_mentions": ["mars"], }, "user": { "id_str": "11348282", "name": "NASA" } }, { "created_at": "Sun Feb 25 18:11:01 +0000 2018", "id_str": "123824267948773378", "text": "", "entities": { "hashtags": [], "user_mentions": ["mars"], }, "user": { "id_str": "11348282", "name": "NASA" } }] } self.responseHastag = [ self.hastag["statuses"][0], self.hastag["statuses"][1] ] self.responseMention = [ self.mention["statuses"][0], self.mention["statuses"][1] ] self.param_makeTweets = self.responseHastag + self.responseMention tweets = [] for tweet_data in self.responseHastag + self.responseMention: tweets.append(Tweet(tweet_data, raw=True)) self.response_fetchTweets = {'Tweets': tweets} self.resquest_get_200_content = self.campaign.to_json()