Send notifications in telegram group [closed] - telegram-bot

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
How can I have my telegramBot send automatically messages in a group?
def handle_event(event):
#print(event)
global amount0In
global amount1Out
global amount1In
global amount0Out
amount0In = event['args']['amount0In']
amount1Out = event['args']['amount1Out']
amount1In = event['args']['amount1In']
amount0Out = event['args']['amount0Out']
if amount0In and amount1Out != 0:
print(f"Token Sold {amount0In /10**18}, and eth {amount1Out/10**18}")
buy()
else:
print(f"Token Bought {amount0Out /10**18}, and eth {amount1In/10**18}")
sell()
def buy(update,context):
buyMessage = f"Buy!!!!\n💴: {amount1In/10**18}\nToken Bought: {amount0Out /10**18} \n"
update.message.reply_text(buyMessage)
def sell(update, context):
sellMessage = f"Sell!!!!\n💴: {amount1In/10**18}\nToken Sold: {amount0Out /10**18} \n"
update.message.reply_text(sellMessage)
In case the IF statement is met I want to send a message to a telgram group, however I cant execute the update message this way, because I keep getting this error:
TypeError: buy() missing 2 required positional arguments: 'update' and 'context'
How can I fix this?

To send a message, all you need is an instance of telegram.Bot. Please have a look at the introduction to the API for more details.
The functions buy and sell look like callback functions for handler. Since you are apparently not using python-telegram-bots handler setup to handle the event, there is no sense in defining those functions to accept the update and context arguments.
Disclaimer: I'm currently the maintainer of python-telegram-bot.

Related

Why is my SQL Server CASE statement not working as expected [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
I am trying to align these classifications using a CASE statement but the table build is still returning an incorrect value for the 3rd column in row 2 of the results (below). Can you help me figure out why? -- I'm really scratching my head here?
Code and screenshot below:
image highlighting the problem
SELECT DISTINCT
dom_id = 5,
stg1.PVDESC,
'bus_segment_test' =
CASE
WHEN stg1.PVDESC LIKE '%Process Monitoring%'
THEN stg1.PVDESC
ELSE 'Environmental Monitoring'
END,
comm_bus_segment_test =
CASE
WHEN 'bus_segment_test' LIKE '%Process Monitoring%'
THEN 'Process Monitoring'
ELSE 'Environmental Monitoring'
END
FROM
CDW_Staging.dbo.STG_1_ERP0005_BILL AS stg1
Row 2 in the following output table shows the undesired results (because incorrectly showing 'Environmental Monitoring' in Col3 when it should say 'Process Monitoring'):
dom_id
PVDESC
bus_segment_test
comm_bus_segment_test
5
BioAerosol
Environmental Monitoring
Environmental Monitoring
5
Process Monitoring
Process Monitoring
Environmental Monitoring
5
Franklin Systems
Environmental Monitoring
Environmental Monitoring
5
Franklin
Environmental Monitoring
Environmental Monitoring
5
West Columbia
Environmental Monitoring
Environmental Monitoring
5
Coal
Environmental Monitoring
Environmental Monitoring
Your second CASE statement is comparing the string 'bus_segment_test' to '%Process Monitoring%'. I'd change WHEN 'bus_segment_test' LIKE '%Process Monitoring%' THEN 'Process Monitoring' to WHEN stg1.PVDESC LIKE '%Process Monitoring%' THEN 'Process Monitoring'

Sometimes the Google Geocoding API returns a 500 server error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Sometimes the Google Maps API returns a 500 server error response according to German postal codes and i cannot understand why.
I hope it is specific enough.
Any ideas?
https://maps.googleapis.com/maps/api/geocode/json?key={api_key}&address={postal_code}&language=de&region=de&components=country:DE&sensor=false
Since you specify that the problem is not a given address but a seemingly "random" behavior, this may fall under a documented behavior of other "famous" API.
As for other cases, the recommended strategy is Exponential backoff for the Geocoding API, which basically means that you have to retry after a certain delay.
In case the above link goes down or changes, I'm quoting the article:
Exponential Backoff
In rare cases something may go wrong serving your request; you may receive a 4XX or 5XX HTTP response code, or the TCP connection may simply fail somewhere between your client and Google's server. Often it is worthwhile re-trying the request as the followup request may succeed when the original failed. However, it is important not to simply loop repeatedly making requests to Google's servers. This looping behavior can overload the network between your client and Google causing problems for many parties.
A better approach is to retry with increasing delays between attempts. Usually the delay is increased by a multiplicative factor with each attempt, an approach known as Exponential Backoff.
For example, consider an application that wishes to make this request to the Google Maps Time Zone API:
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=YOUR_API_KEY
The following Python example shows how to make the request with exponential backoff:
import json
import time
import urllib
import urllib2
def timezone(lat, lng, timestamp):
# The maps_key defined below isn't a valid Google Maps API key.
# You need to get your own API key.
# See https://developers.google.com/maps/documentation/timezone/get-api-key
maps_key = 'YOUR_KEY_HERE'
timezone_base_url = 'https://maps.googleapis.com/maps/api/timezone/json'
# This joins the parts of the URL together into one string.
url = timezone_base_url + '?' + urllib.urlencode({
'location': "%s,%s" % (lat, lng),
'timestamp': timestamp,
'key': maps_key,
})
current_delay = 0.1 # Set the initial retry delay to 100ms.
max_delay = 3600 # Set the maximum retry delay to 1 hour.
while True:
try:
# Get the API response.
response = str(urllib2.urlopen(url).read())
except IOError:
pass # Fall through to the retry loop.
else:
# If we didn't get an IOError then parse the result.
result = json.loads(response.replace('\\n', ''))
if result['status'] == 'OK':
return result['timeZoneId']
elif result['status'] != 'UNKNOWN_ERROR':
# Many API errors cannot be fixed by a retry, e.g. INVALID_REQUEST or
# ZERO_RESULTS. There is no point retrying these requests.
raise Exception(result['error_message'])
if current_delay > max_delay:
raise Exception('Too many retry attempts.')
print 'Waiting', current_delay, 'seconds before retrying.'
time.sleep(current_delay)
current_delay *= 2 # Increase the delay each time we retry.
tz = timezone(39.6034810, -119.6822510, 1331161200)
print 'Timezone:', tz
Of course this will not resolve the "false responses" you mention; I suspect that depends on data quality and does not happen randomly.

How to get device names based on group name in zenoss? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Is there any API to get all the device names under the same group in zenoss?
Please point me in the right direction.
I am using Python for querying the devices under zenoss group.
Key is sending request with data='{"action":"DeviceRouter", "method":"getDevices","data":[{"uid":"/zport/dmd/Devices/"}],"tid":1}')
import requests
def getZenossDeviceList(zenossURI, username, password, data):
try:
s = requests.Session()
s.auth = (username, password)
s.headers["Content-Type"] = "application/json"
r = s.post(zenossURI, data=data, timeout=(3.05, 30));
except Exception as ex:
raise Exception("getZenossDeviceList: {0}",ex )
else:
if r.status_code == requests.codes.ok:
return r.json()
else:
raise Exception("getZenossDeviceList: {0}", r.reason)
def getServerList(username,password):
hostList = []
zenossURI="https://<ZENOSSS_SERVER_IP>/zport/dmd/device_router"
try:
r = getZenossDeviceList(zenossURI, username, password,\
data='{"action":"DeviceRouter", "method":"getDevices","data":[{"uid":"/zport/dmd/Devices/<AbsolutePath_for_Groupname>"}],"tid":1}')
print r
except Exception as e:
print "Exception", e

Issue tracking system for an hospital? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've a friend working in an hospital and he asked for an issue tracking system.
Currently they are using only mails. I thought to Jira or Trac, but they use
"programming terms" like "bug" or "patch".
I don't want to spend time customizing, do you know any better solution/software?
I used Trac to implement issue tracking for managing the operations of a building. It is quite configurable, so I was able to conceal the software-bug-oriented wording without a lot of effort, though the admin interface.
I applied a trivial patch to Trac so that it displays boolean values as Y and N rather than the the "computerese" 1 and 0, and also, so that the false value is displayed a blank. (This is better in a columnar report where you have boolean columns, and you just want to clearly see where the Y values are; they are harder to see in a grid of Y's and N's).
Here it is below. Everything else, I did easily through the admin interface.
Index: pyshared/trac/ticket/web_ui.py
===================================================================
--- pyshared.orig/trac/ticket/web_ui.py 2011-09-16 11:59:40.000000000 -0700
+++ pyshared/trac/ticket/web_ui.py 2011-09-16 12:11:31.000000000 -0700
## -1120,7 +1120,7 ##
elif type_ == 'checkbox':
value = ticket.values.get(name)
if value in ('1', '0'):
- field['rendered'] = value == '1' and _('yes') or _('no')
+ field['rendered'] = value == '1' and 'yes' or ''
# ensure sane defaults
field.setdefault('optional', False)
Index: pyshared/trac/ticket/query.py
===================================================================
--- pyshared.orig/trac/ticket/query.py 2011-09-16 14:36:51.000000000 -0700
+++ pyshared/trac/ticket/query.py 2011-09-16 14:37:10.000000000 -0700
## -294,9 +294,9 ##
val = datetime.fromtimestamp(int(val or 0), utc)
elif field and field['type'] == 'checkbox':
try:
- val = bool(int(val))
+ val = val == '1' and 'Y' or ''
except TypeError, ValueError:
- val = False
+ val = ''
result[name] = val
results.append(result)
I know you said that you didn't want to time customizing, but I am afraid you are just out of luck on that. I doubt that there is any issue tracking system out there that will give you exactly what you want without customizing (or without exorbitant fees). So I will still recommend JIRA.
JIRA is incredibly customizable. We use it in our organization for tracking issues of many types from software issue tracking, to Vehicle reservations, to building maintenance work order requests, purchase request, and more. We also have plans to customize it for our students (I work in a college) to be able to request assistance with registration, submit feedback, and more.
JIRA is incredibly robust and, once you get the hang of it, not terrible to configure. I won't lie. Configuring JIRA, at first, is a chore and can be difficult to get a handle on. But there is a great book from O'Reilly called Jira Administration that helped me understand it all much better. And it is quite a small book (187 pages or so), so it is not filled with a bunch of fluff. It is just great and useful information.
We use JIRA Dashboards, Issue type customizations, notification schemes, permission schemes, issue type security, custom workflows, custom screens and forms, plugins, the Web Service APIs, and more. It really is a fantastic system.

Apache Tomcat 5.5.23 error. HTTP Status 500 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Following is the stack trace
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(jasper5-compiler-5.5.23.jar.so)
org.apache.jasper.servlet.JspServletWrapper.getServlet(jasper5-compiler-5.5.23.jar.so)
org.apache.jasper.servlet.JspServletWrapper.service(jasper5-compiler-5.5.23.jar.so)
org.apache.jasper.servlet.JspServlet.serviceJspFile(jasper5-compiler-5.5.23.jar.so)
org.apache.jasper.servlet.JspServlet.service(jasper5-compiler-5.5.23.jar.so)
javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-api-5.5.23.jar.so)
looks like this code is compiled pre generics support,
An error occurred at line: 236 in the jsp file: /dashboard_new.jsp
Syntax error, parameterized types are only available if source level is 5.0
recompile the code with jdk >= 1.5 would be my guess or maybe the tomcat server is setup to use a jdk < 1.5
hope that helps
EDIT:
all of the errors apart from the one below seem to be a compiled version issue.
this one :
An error occurred at line: 338 in the jsp file: /dashboard_new.jsp
Incompatible conditional operand types String and int
335: out.println( "<td valign=\"top\">" + frameBean.getLatitude() + "</td>" );
336: out.println( "<td valign=\"top\">" + frameBean.getLongitude() + "</td>" );
seems to be trying to concatonate Strings and Integers. this should also work in later versions of java, i think.