Beispiel #1
0
	def info(self,name):

		name = name.strip()

		if name in self.foodmap:
			print(self.foodmap[name].printout(header=True), file=sys.stderr)
			return name

		#Search objects for closest match
		arg_name = name	#store

		found = self.search(name)
		res = len(found)

		if res == 0:
			text_options = ("manually insert", "search online")
			char_options = ("i", "s")

			res = Common.userSingleListPrompt("\nCannot find: \"%s\"" % name, text_options, char_options)

			if res == 'i':
				self.insert(name, [arg_name])
				return name.lower()
			elif res == 's':
				f = MiniFSChecker.FHandler(name).found
				if f==-1:
					exit(0)

				self.insertAll(f, [arg_name,"FS_online"] )
				return f.name

			exit(0)

		# Found something, print
		INFO("\nMatched:", end=' ')
		res = Common.choice(found)

		if res==-1:
			INFO("None")
			if Common.ynprompt('Search online? '):
				f = MiniFSChecker.FHandler(name).found
				if f==-1:exit(0)
				self.insertAll(f, [arg_name, "FS_online"]) # Nothing found, include input name as a tag
				name = f.name
			else:
				#Manual insert
				self.insert(name, [arg_name])		# Nothing ...
		else:
			name = res.name
		return name
Beispiel #2
0
    def makeTotals(self, date, showPie=False, printme=False):
        self.read(date)

        kC_total = 0
        carb_total = Carb(0, 0, 0)
        protein_total = 0
        fat_total = 0

        if len(self.foodlog) == 0:
            INFO("nothing logged for date: %s" % date)
            prevD = previousDay(ymd2secs(date.split('/')))
            if ynprompt("Print day before that (%s)? " % prevD):
                return self.makeTotals(prevD, showPie, printme)

        if printme:
            INFO('\n' * 10)
            Yemek.printFullHeader()

        after_L_head = False
        after_6_head = False

        for y in self.foodlog:
            scyem = y.scaled()

            kC_total += scyem.kC
            carb_total.add(scyem.carb)
            protein_total += scyem.prot
            fat_total += scyem.fat

            if printme:
                if not (after_L_head) and (y.hour >= 12):
                    print('        ===== Lunch ====', file=sys.stderr)
                    after_L_head = True
                if not (after_6_head) and (y.hour >= 18):
                    print('        ===== Dinner ====', file=sys.stderr)
                    after_6_head = True
                print(scyem.printout(), file=sys.stderr)

        self.pie = PieChart(carb_total,
                            protein_total,
                            fat_total,
                            kC_total,
                            self.macrofile,
                            Yemek.buffer - 8,
                            8,
                            printme=showPie)

        return kC_total, carb_total, protein_total, fat_total
Beispiel #3
0
	def search(self,name):
		searchname = name.split()  #d[0].strip()
		#print searchfoods, searchname

		found=[];
		for avail_food, obj in self.foodmap.items():
			#words
			word_match = 0
			for ss in searchname:
				for s in avail_food.split():
					if ss.strip() in s.strip():
						word_match += 1
			if word_match != 0:
				found.append( [obj, word_match] )


		if len(found)==0:
			INFO("Searching tags...")
			for avail_food, obj in self.foodmap.items():
				word_match = 0
				for ss in searchname:
					for tag in obj.tags.tags:
						if ss.strip() in tag:
							word_match += 1
				if word_match != 0:
					found.append( [obj, word_match] )

		def sorter(x):return x[1]

		return [x for x,y in sorted(found, key=sorter, reverse=True)]
Beispiel #4
0
	def insert(self,name, input_search=[]):
		INFO("Inserting new food:", name)
		per,unit = Common.amountsplit(input("Per Unit (e.g. '100g'): ").strip())
		kc, carb_total, carb_sugar, carb_fibre , prot, fat = input("kCal Carb Sug Fibr Prot Fat: ").split()

		carbs = Carb(carb_total, carb_fibre, carb_sugar)
		y = Yemek(name, kc, carbs, prot, fat, per, unit)

		self.insertAll(y, input_search)
Beispiel #5
0
    def convert(self, fr, to):

        if fr == "":
            INFO("No unit given, assuming 'lb'", file=stderr)
            fr = 'lb'

        fr = self.def_map[fr]
        to = self.def_map[to]

        return self.con_map[(fr, to)]
Beispiel #6
0
    def set(self, lbls, setmorn, finalprint=False):
        if setmorn:
            if self.morn != -1:
                INFO("Morning already set:")
                print(self.printout(header=True, filler=True))
                if (ynprompt('Overwrite? ')):
                    self.morn = lbls
            else:
                self.morn = lbls
        else:
            if self.night != -1:
                INFO("Night already set:")
                print(self.printout())
                if (ynprompt('Overwrite? ')):
                    self.night = lbls
            else:
                self.night = lbls

        if finalprint:
            print(self.printout(True))
Beispiel #7
0
	def insertAll(self, yem, input_search=[]):
		# Tag prompt
		user_input_tags = Tags.tagprompt()

		if user_input_tags!=-1:
			yem.tags.insertList(user_input_tags)


		name = yem.name.strip().lower()
		self.foodmap[name] = yem
		INFO("Inserted \"%s\"" % name)
		self.write()
Beispiel #8
0
    def checkThisMorning(self):
        if self.today in self.weightlogmap:
            w = self.weightlogmap[self.today]
            if self.nighttime and w.morn == -1:
                INFO("Night now, morning not set. ")
                if (ynprompt('Set morning? ')):
                    self.logprompt(self.today, isDay=True)
                    return True

            if not (self.nighttime) and w.morn != -1:
                self.logprompt(self.today, isDay=True)
                return True

            return False  #nothing changed

        #Else log a new morning at night
        if self.nighttime:
            INFO("Night now, morning not set. ")
            if (ynprompt('Set morning? ')):
                self.logprompt(self.today, isDay=True)
                return True
        return False  #nothing changed
Beispiel #9
0
    def checkLastNight(self):
        if self.yesterday in self.weightlogmap:
            w = self.weightlogmap[self.yesterday]
            if w.night == -1:
                INFO("Last night not set")
                if (ynprompt('Set last night? ')):
                    self.logprompt(self.yesterday, isDay=False)
                    return True

                RESULT("[Ignoring last night]")
                if ynprompt('Ignore permanently? '):
                    self.log(self.yesterday, 0, False)
                    RESULT("[Ignoring last night permanently]")
                    return True

                RESULT("[Temporarily ignored last night, moving on..]\n")

        return False  #nothing changed
Beispiel #10
0
	def updateListInfo(self):
		for name in list(self.foodmap.keys()):
			food = self.foodmap[name]

			if not((food.carb.sugar ==0 and food.carb.fibre==0) and (food.carb.total == food.carb.bad)):
				continue

			if "FS_online" not in food.tags.tags:continue

#			if name != 'chicken drumstick (skin eaten)':continue

			INFO("Check:")
			print(food.printout(pre="---"))
			f = MiniFSChecker.FHandler(food.name, food).found
			if f!=-1:
				del self.foodmap[name]
				self.foodmap[f.name.lower()] = f
				self.write()

		self.write()
Beispiel #11
0
    def __init__(self, query, foodobj=0):
        INFO("\r\tChecking online...", end=' ')
        self.query = HTMLMethods.toHTMLChars(query)

        try:
            self.pagedata = uopen(FHandler.query_url + self.query).read()
        except URLError:
            print(" stopped, no connection?")
            exit(-1)

#		# offline saved
#		print(self.pagedata)
#		exit(0)
#		self.pagedata = open("test_sub.html").read()

        self.results = self.ParseResults()
        if foodobj == 0:
            self.found = self.resHandler()
        else:
            #Check current food obj against results list
            self.found = self.checkFoodHomology(foodobj)
Beispiel #12
0
                user_foodlist = normpath(tokens[1].strip())
            elif tokens[0].startswith('user_foodlog'):
                user_foodlog = normpath(tokens[1].strip())
            elif tokens[0].startswith('user_weightlog'):
                user_weightlog = normpath(tokens[1].strip())

        # if not all found, defaults are used
        conf.close()
else:
    with open(user_config_file, 'w') as conf:
        conf.write('user_foodlist = %s\n' % user_foodlist)
        conf.write('user_foodlog = %s\n' % user_foodlog)
        conf.write('user_weightlog = %s\n' % user_weightlog)
        conf.close()

    INFO("default list, log, weight file locations have been set at: %s" %
         user_config_file)


class Config:
    @staticmethod
    def resolveAllPaths():  # called from main
        Config.resolvePath(user_foodlist)
        Config.resolvePath(user_foodlog)
        Config.resolvePath(user_weightlog)

    @staticmethod
    def resolvePath(filepath):
        Config.__touch(filepath)

    @staticmethod
    def __touch(filename):