Advertisement
lzedl

Untitled

Nov 9th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf8 -*-
  3. import pynotify
  4. import requests
  5. import urllib2
  6. import json
  7. import sys
  8.  
  9.  
  10. API_KEY = '<paste_here>'
  11.  
  12.  
  13. def main():
  14.     pynotify.init('Basic')
  15.  
  16.     for word in sys.stdin:
  17.         response = requests.get(
  18.             "https://translate.yandex.net/api/v1.5/tr.json/translate",
  19.             params={
  20.                 'key': API_KEY,
  21.                 'text': urllib2.quote(word),
  22.                 'lang': 'ru',
  23.                 'format': 'plain',
  24.                 'options': '1'
  25.             }
  26.         )
  27.  
  28.         data = response.json()
  29.  
  30.         n = pynotify.Notification(u"Перевод", data['text'][0])
  31.         # n.set_timeout(pynotify.EXPIRES_NEVER)
  32.         n.show()
  33.  
  34.  
  35. if __name__ == "__main__":
  36.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement