コード例 #1
0
ファイル: calc.py プロジェクト: kanhan258/phbot
def run(msg, matches):
    receiver = utils.get_receiver(msg)
    exp = matches[0]
    path = "http://api.mathjs.org/v1/"
    payload = {'expr': exp}
    if len(matches) > 1:
        payload.update({'precision': matches[1]})
    gcb = utils.gac(cb, receiver)
    utils.mp_requests('GET', path, gcb, params=payload)
コード例 #2
0
ファイル: calc.py プロジェクト: Iran-Python/pybotgram
def run(msg, matches):
    receiver = utils.get_receiver(msg)
    exp = matches[0]
    path = "http://api.mathjs.org/v1/"
    payload = {'expr': exp}
    if len(matches) > 1:
        payload.update({'precision': matches[1]})
    gcb = utils.gac(cb, receiver)
    utils.mp_requests('GET', path, gcb, params=payload)
コード例 #3
0
 def run(self, msg, matches):
     receiver = utils.get_receiver(msg)
     pattern = matches[0]
     userid = msg.src.id
     if pattern == "photo" or pattern == "document":
         if userid in self.users:
             # Check if he is in the list
             cb = utils.gac(self.callback, receiver, userid)
             getattr(msg, "load_{}".format(pattern))(cb)
     if pattern == "start":
         self.users.add(userid)
         return "You can send me an image now :)"
     if pattern == "stop":
         if userid in self.users:
             self.users.remove(userid)
コード例 #4
0
 def callback(self, success, path, receiver, userid):
     if userid in self.users:
         self.users.remove(userid)
     if success:
         # check if it's an image
         name = path.split("/")[-1].split(".")[0]
         extens = path.split("/")[-1].split(".")[-1]
         if extens.lower() not in ["png", "jpg", "jpeg", "gif"]:
             self.remove_path(True, True, path)
             receiver.send_msg("Sorry, that wasn't an accepted document. I accept png, jpg and gif.")
             return
         npath = "./{}.webp".format(name)
         try:
             im = Image.open(path).convert("RGBA")
             im.save(npath, "WEBP")
             receiver.send_document(npath, utils.gac(self.remove_path, npath))
         except:
             os.remove(npath)
         finally:
             os.remove(path)
コード例 #5
0
def run(msg, matches):
    currencies = [
        "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN",
        "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL",
        "BSD", "BTC", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLF",
        "CLP", "CNH", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DEM", "DJF",
        "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FIM", "FJD", "FKP",
        "FRF", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD",
        "HNL", "HRK", "HTG", "HUF", "IDR", "IEP", "ILS", "INR", "IQD", "IRR",
        "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW",
        "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL",
        "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO",
        "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK",
        "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKG", "PKR", "PLN",
        "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG",
        "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "STD", "SVC", "SYP", "SZL",
        "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH",
        "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD",
        "XDR", "XOF", "XPF", "YER", "ZAR", "ZMK", "ZMW", "ZWL"
    ]

    fromCur = matches[0].upper()
    amount = matches[1]
    toCur = matches[2].upper()

    if fromCur.isdigit():
        fromCur, amount = amount.upper(), fromCur

    if fromCur not in currencies:
        return "ERROR: currency \"" + fromCur + "\" is not recognized"

    if toCur not in currencies:
        return "ERROR: currency \"" + toCur + "\" is not recognized"

    url = "https://www.google.com/finance/converter?a=" + \
          amount + "&from=" + fromCur + "&to=" + toCur

    receiver = utils.get_receiver(msg)

    gcb = utils.gac(cb, receiver, amount, fromCur, toCur)
    utils.mp_requests('GET', url, gcb)
コード例 #6
0
ファイル: money.py プロジェクト: Iran-Python/pybotgram
def run(msg, matches):
    currencies = ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", "CNH", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DEM", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "IEP", "ILS", "INR", "IQD", "IRR", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKG", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XDR", "XOF", "XPF", "YER", "ZAR", "ZMK", "ZMW", "ZWL"]

    fromCur = matches[0].upper()
    amount = matches[1]
    toCur = matches[2].upper()

    if fromCur.isdigit():
        fromCur, amount = amount.upper(), fromCur

    if fromCur not in currencies:
        return "ERROR: currency \"" + fromCur + "\" is not recognized"

    if toCur not in currencies:
        return "ERROR: currency \"" + toCur + "\" is not recognized"

    url = "https://www.google.com/finance/converter?a=" + \
          amount + "&from=" + fromCur + "&to=" + toCur

    receiver = utils.get_receiver(msg)

    gcb = utils.gac(cb, receiver, amount, fromCur, toCur)
    utils.mp_requests('GET', url, gcb)