Ejemplo n.º 1
0
def get_statistics(b1, b2, a2, a3):
    a_perc = b_perc = b1a3_perc = 0
    if not (b1 == 0 or b2 == 0):
        b_perc = (b1 / b2 - 1) * 100
        if not a3 == 0:
            b1a3_perc = ((b1 / 11) / (a3 / 10) - 1) * 100
    if not (a2 == 0 or a3 == 0):
        a_perc = (a3 / a2 - 1) * 100

    message = strings.separator
    message += "\nRAPPORTI SU MEDIE\n"
    message += "\nB1/B2: %.2f" % b_perc + "% " + emoji.get_emoji(b_perc, 1)
    message += "\nA3/A2: %.2f" % a_perc + "% " + emoji.get_emoji(a_perc, 2)
    message += "\nB1/A3 stringa: %.2f" % b1a3_perc
    message += "% " + emoji.get_emoji(b1a3_perc, 2)
    return message
Ejemplo n.º 2
0
async def mailing():
	loop  =  asyncio.get_event_loop()
	subscriptions = db.get_subscriptions()
	for s in subscriptions:
		user_time = str(db.get_time(s[1])[0][0])
		city = str(db.subscription_city(s[1])[0])
		city = city[2:-3]
		observation = mgr.weather_at_place(city)
		w = observation.weather
		reference_time_1 = str(w.reference_time('iso')[11:16])[0:-3]
		if user_time == reference_time_1:
			fc1 = mgr.forecast_at_place(city,'3h')
			f = fc1.forecast
			reception_date = str(f)
			reception_date = reception_date[55:65]
			answer = ""
			for w in f:
				time = str(w.reference_time('iso') + 4)
				date = time[:10]
				if date == reception_date:
					time = str(time[11:16])
					temp = str(w.temperature('celsius')["temp"])
					detailed_status = w.detailed_status
					not_detailed = w.status
					answer1 = "{0}:\n{1}{3} {2}ºC\n\n".format(time,detailed_status,temp,emoji.get_emoji(not_detailed))
					answer = answer + answer1
			try:
				await bot.send_message(s[1],"⏰Время погоды🔔:")
				await bot.send_message(s[1],"Прогноз города {0}:\n{1}".format(city,answer))
			except:
				pass
Ejemplo n.º 3
0
async def by_massage(message: types.Message):
	if ((message.text[0:4].capitalize() == 'Push') and (message.from_user.id == 214196761)):
		push_text = str(message.text[5:])
		await message.answer('Рассылка активирована')
		name = 0
		try:
			while name < (db.all_users()[-1][0]-4):
				await bot.send_message(db.all_users()[name][1], push_text)
				name +=1
		except:
			await bot.send_message(214196761, "ошибка рассылки для " + str(db.all_users()[name][6]))
	else:
		try:
			observation = mgr.weather_at_place(message.text)
			w = observation.weather
			detailed_status = w.detailed_status
			not_detailed = w.status
			answer = ("В городе "+ message.text + " сейчас Ясно"+  str(emoji.get_emoji(not_detailed)) +"\n")
			answer += ("Температура: " + str(w.temperature('celsius')["temp"]) + "ºC \n")
			answer += ("Скорость ветра: " + str(w.wind()["speed"]) + "м/с\n")
			answer += ("Влажность: " + str(w.humidity) + "% \n\n")
			await message.answer(answer)
		except:
			await bot.send_message(message.chat.id, 'похоже произошла внутренняя ошибка \nпопробуй ещё раз')
		if db.subscriber_exists(message.from_user.id) == 'da':
			pass
		else:
			# если юзера нет в базе, добавляем его
			db.add_subscriber(message)
			await bot.send_message(214196761, '{0} added\n{1} {2} \n{3}'.format(message.from_user.id, message.from_user.first_name, message.from_user.last_name, message.from_user.username))
Ejemplo n.º 4
0
async def unsubscribe(message: types.Message):
	city = str(message.text[10:])
	if city == '':
		await message.answer('Используйте: /forecast "город"')
		if db.subscriber_exists(message.from_user.id) == 'da':
			pass
		else:
			db.add_subscriber(message, False)
			await bot.send_message(214196761, '{0} added\n{1} {2} \n{3}'.format(message.from_user.id, message.from_user.first_name, message.from_user.last_name, message.from_user.username))
	else:
		observation = mgr.weather_at_place(city)
		w = observation.weather
		fc1 = mgr.forecast_at_place(city,'3h')
		f = fc1.forecast
		reception_date = str(f)
		reception_date = reception_date[55:65]
		answer = ""
		for w in f:
			time = str(w.reference_time('iso'))
			date = time[:10] 
			if date == reception_date:
				time = str(time[11:16])
				temp = str(w.temperature('celsius')["temp"])
				detailed_status = w.detailed_status
				not_detailed = w.status
				answer1 = "{0}:\n{1}{3} {2}ºC\n\n".format(time,detailed_status,temp,emoji.get_emoji(not_detailed))
				answer = answer + answer1
		await message.answer('прогноз для города: ' +city + '\n\n' + answer)
		if db.subscriber_exists(message.from_user.id) == 'da':
			pass
		else:
			# если юзера нет в базе, добавляем его с неактивной подпиской
			db.add_subscriber(message, False)
			await bot.send_message(214196761, '{0} added\n{1} {2}\n{3}'.format(message.from_user.id, message.from_user.first_name, message.from_user.last_name, message.from_user.username))
Ejemplo n.º 5
0
def statistiche_mese(actB1, actB2, actA2, actA3):
    message = "\nRAPPORTI SU PROD MENSILE\n"
    cmB1 = actB1 - meseB1
    cmB2 = actB2 - meseB2
    cmA2 = actA2 - meseA2
    cmA3 = actA3 - meseA3
    # print('B1: ', actB1, meseB1, cmB1)
    # print('B2: ', actB2, meseB2, cmB2)
    # print('A2: ', actA2, meseA2, cmA2)
    # print('A3: ', actA3, meseA3, cmA3)
    B1B2 = (cmB1 / cmB2 - 1) * 100
    diffB1B2 = cmB1 - cmB2
    A3A2 = (cmA3 / cmA2 - 1) * 100
    diffA3A2 = cmA3 - cmA2
    B1A3 = ((cmB1 / 11) / (cmA3 / 10) - 1) * 100
    diffB1A3 = (cmB1 / 11) - (cmA3 / 10)
    to_send = "%.2f" % B1B2 + "% " + emoji.get_emoji(B1B2, 1)
    message += "\nB1/B2: " + to_send + " (%.2f" % diffB1B2 + "kW)"
    to_send = "%.2f" % A3A2 + "% " + emoji.get_emoji(A3A2, 2)
    message += "\nA3/A2: " + to_send + " (%.2f" % diffA3A2 + "kW)"
    to_send = "%.2f" % B1A3 + "% " + emoji.get_emoji(B1A3, 2)
    message += "\nB1/A3 str: " + to_send + " (%.2f" % diffB1A3 + "kW)"
    return message
Ejemplo n.º 6
0
async def by_location(message: types.Message):
	f = open('location.txt', 'a')
	f.write(str(message.from_user.id) + '  ' + str(message.location.latitude) + '  ' + str(message.location.longitude) + '\n')
	f.close()
	
	await message.answer('показана погода возле ближайшей метеостанции')
	observation = mgr.weather_at_coords(int(message.location.latitude), int(message.location.longitude))
	w = observation.weather
	l = observation.location
	detailed_status = w.detailed_status
	not_detailed = w.status
	answer = ("В городе "+ l.name + " сейчас Ясно"+  str(emoji.get_emoji(not_detailed)) +"\n")
	answer += ("Температура: " + str(w.temperature('celsius')["temp"]) + "ºC \n")
	answer += ("Скорость ветра: " + str(w.wind()["speed"]) + "м/с\n")
	answer += ("Влажность: " + str(w.humidity) + "% \n\n")
	await message.answer(answer)

	if db.subscriber_exists(message.from_user.id) == 'da':
		pass
	else:
		# если юзера нет в базе, добавляем его
		db.add_subscriber(message)
		await bot.send_message(214196761, '{0} added\n{1} {2} \n{3}'.format(message.from_user.id, message.from_user.first_name, message.from_user.last_name, message.from_user.username))
Ejemplo n.º 7
0
def get_statistics(a_strings, b_strings):
    message = "\nRAPPORTI SU PROD ODIERNA\n"
    to_send = "%.2f" % b_strings[2] + "% " + emoji.get_emoji(b_strings[2], 1)
    diffb1b2 = " (%.1f" % (b_strings[0] - b_strings[1]) + "kW)"
    message += "\nB1/B2: " + to_send + diffb1b2
    to_send = "%.2f" % a_strings[2] + "% " + emoji.get_emoji(a_strings[2], 2)
    diffa3a2 = " (%.1f" % (a_strings[1] - a_strings[0]) + "kW)"
    message += "\nA3/A2: " + to_send + diffa3a2
    b1overa3 = ((b_strings[0] / 11) / (a_strings[1] / 10) - 1) * 100
    to_send = "%.2f" % b1overa3 + "% " + emoji.get_emoji(b1overa3, 1)
    diffb1a3 = " (%.1f" % (b_strings[0] / 11 - a_strings[1] / 10) + "kW)"
    message += "\nB1/A3 str: " + to_send + diffb1a3
    message += strings.separator
    message += statistiche_mese(b_strings[5], b_strings[6], a_strings[5], a_strings[6])
    message += strings.separator
    message += "\nRAPPORTI SU PROD TOTALE\n"
    message += "             [dopo 24/02][totale]\n"
    # calcola il rapporto di produzione dal 25/02/16
    B1postFix = b_strings[5] - fixB1
    B2postFix = b_strings[6] - fixB2
    B1B2postFix = (B1postFix / B2postFix - 1) * 100
    A2postFix = a_strings[5] - fixA2
    A3postFix = a_strings[6] - fixA3
    A3A2postFix = (A3postFix / A2postFix - 1) * 100
    B1A3postFix = ((B1postFix / 11) / (A3postFix / 10) - 1) * 100
    to_send = "[%.2f" % B1B2postFix + "% " + emoji.get_emoji(B1B2postFix, 1)
    to_send += "][%.2f" % b_strings[3] + "% " + emoji.get_emoji(b_strings[3], 1)
    message += "\nB1/B2: " + to_send + "]"
    to_send = "[%.2f" % A3A2postFix + "% " + emoji.get_emoji(A3A2postFix, 1)
    to_send += "][%.2f" % a_strings[3] + "% " + emoji.get_emoji(a_strings[3], 2)
    message += "\nA3/A2: " + to_send + "]"
    b2overa3 = ((b_strings[5] / 11) / (a_strings[6] / 10) - 1) * 100
    # to_send = '[%.2f' % B1A3postFix + '% ' + emoji.get_emoji(B1A3postFix, 1)
    to_send = "[%.2f" % B1A3postFix + "%"
    # to_send += '][%.2f' % b2overa3 + '% ' + emoji.get_emoji(b2overa3, 2)
    to_send += "][%.2f" % b2overa3 + "%"
    message += "\nB1/A3 str: " + to_send + "]"
    return message