示例#1
0
def gain(ctx, id):
    """
    Gain XP from Yum4FIT pictures on Instagram
    :param id: Returns the XP gain only from the picture with the ID set as an argument
    :return: XP Gain
    """
    config = ctx.obj['config']
    username = Parser.getUsername(ctx.obj['username'], config)
    password = Parser.getPassword(ctx.obj['password'], config)
    hashtag = Parser.get(config, 'instagram', 'hashtag')
    friendsFile = ctx.obj['friends_file']
    serverURL = ctx.obj['server_url']

    setConfirmed(password, serverURL)

    result = acc.gain(username, password, hashtag, id, friendsFile)

    if not id:
        data = {
            'likes': str(result.likes),
            'level': str(result.level),
            'xp': str(result.xp)
        }
        json_data = json.dumps(data)
        url = ctx.obj['server_url']
        url += 'gain'
        connector.post(url, json_data, password)

    # result is state
    if (id == None):
        click.echo(result.text())
    # result is likes count
    else:
        click.echo("%s: " % id + "%d likes" % result + " (%s XP)" %
                   (result * CONST.XP_FACTOR))
示例#2
0
def add_friend(ctx, username, id):
    data = {"username": username, "post": id}
    json_data = json.dumps(data)
    url = ctx.obj['server_url']
    url += 'addfriend'
    Parser.updateSection(CONST.FRIENDS_FILE, username, id, 'no')
    config = ctx.obj['config']
    password = Parser.getPassword(ctx.obj['password'], config)
    connector.post(url, json_data, password)
示例#3
0
def upload(username, password, path, caption, url):
    """
    Upload photo to Instagram
    :param username: Instagram username
    :param password: Instagram password
    :param path:  Path to picture
    :param caption: Caption enriched with hashtag
    :return:
    """
    login(username, password)
    ig.uploadPhoto(path, caption)
    print('Uploading finished.')
    connector.post(url + 'reload', "", password)
示例#4
0
    def saveRecipe(self, food, config):
        """
        Save the recipe to recipe.cfg file
        :param food: food to save
        :param config: configuration file
        """
        fields = ['name', 'url', 'ingredients', 'picture']
        ingredients = ",".join(food.ingredients)
        values = [food.name, food.url, ingredients, food.picture]
        jsonData = self.buildJson(fields, values)
        url = self.server
        url += 'saverecipe'

        password = Parser.getPassword(None, config)
        connector.post(url, jsonData, password)
        Parser.updateSave(CONST.RECIPE_FILE, 'recipe', fields, values)
示例#5
0
 def gain(self):
     """
     Support function to gain XP from likes
     """
     state = account.gain(self.profile.username, self.password,
                          self.hashtag, None, CONSTANTS.FRIENDS_FILE)
     data = {
         'likes': str(state.likes),
         'level': str(state.level),
         'xp': str(state.xp)
     }
     json_data = json.dumps(data)
     url = Parser.get(self.config, 'server', 'url')
     url += 'gain'
     connector.post(url, json_data, self.password)
     self.loadState()
示例#6
0
    def addFriend(self):
        """
        Support function to add friend using the item chosen by clicking to listWidget of foods
        """
        line = self.w.findChild(QtWidgets.QLineEdit, 'lineFriend')
        friend = line.text()

        if (friend == None or friend == ""):
            return
        else:
            listView = self.w.findChild(QtWidgets.QListWidget, 'listFoods')
            id = listView.currentItem().text()
            if id:
                data = {"username": friend, "post": id}
                json_data = json.dumps(data)
                url = Parser.get(self.config, 'server', 'url')
                url += 'addfriend'
                Parser.updateSection(CONSTANTS.FRIENDS_FILE, friend, id, 'no')
                connector.post(url, json_data, self.password)
示例#7
0
def setConfirmed(password, url):
    response = connector.post(url + 'confirmated', "", password)
    parser = Parser.parse(CONST.FRIENDS_FILE)
    friends = parser.sections()
    if not response:
        return
    data = json.loads(response.text)

    sections = []
    fields = []
    for local in friends:
        for new in data:
            extern = new.split('--')[0]
            if extern == local:
                sections.append(local)
                fields.append(data[new])

    for s in sections:
        for f in fields:
            Parser.updateSection(CONST.FRIENDS_FILE, s, f, 'yes')