Skip to content

sudaning/Fneko

Repository files navigation

Welcome to Neko

Version Supported-python-version Build Status Coverage Star Fork MIT License

Introduction

pyFneko is a pure Python library designed to making magic to code for Neko. You can use pyFneko to making magic beautiful. In /scripts , there are some scripts written by me for daily use.

Installation

  1. Via pip
    pip install pyFneko
  2. Via easy_install
    easy_install pyFneko
  3. From source(recommend)
    cd third-party && tar zxf swig-3.0.12.tar.gz && cd swig-3.0.12 && ./configure && make && make install
    python setup.py install

upgrading

  1. Via pip
    pip install --upgrade pyFneko

Examples

  • ProcBar
import time  
from neko import ProcBar, color_str  
p = ProcBar(mod='details')  
total = 56  
p.set_details(total, widget_type="percent").start("Dance up...")  
for i in range(0, total + 1):  
    if p.move():  
    time.sleep(0.1)  
p.stop(color_str("ending", "sky_blue"))
  • Ssh
import sys
from neko import Ssh
s = Ssh('10.9.0.115', username = 'root', password = 'root')
stdin, stdout, stderr = s.exec_command('ls') 
for l in stdout.readlines():
    sys.stdout.write(l)
  • tcpdump
from neko import tcpdump
t = tcpdump(eth='eth0', w='test.pcap', port=10002)
if t.run():
    t.terminate(5)
  • redisCluterBee
from neko import redisCluterBee
r = redisCluterBee('10.9.0.115:7000,10.9.0.115:7001')
print(r.set('123',456))
print(r.get('123'))
print(r.set('789','aaa'))
print(r.get('sf'))
print(r.get('789'))
print(r.get('1234'))
print(r.incr('total', 100))
print(r.incr('total', 200))
print(r.decr('total', 50))
print(r.hset('city', 'cq', '023'))
print(r.hset('city', 'bj', '010'))
print(r.hget('city', 'sz'))
print(r.hget('city', 'cq'))
print(r.hgetall('city'))
  • esl
from neko import ESLEvent
class MyEvent(ESLEvent):
    # overwrite function channel_event
    def channel_event(self, event):
        event_name = event.getHeader("Event-Name")
        event_sub_name = event.getHeader("Event-Subclass")

        if event_name in ['CHANNEL_CREATE']:
            uuid = event.getHeader("unique-id")
            session_id = event.getHeader("variable_session_id")
            call_dir = event.getHeader("Caller-Direction")
            sip_call_id = event.getHeader("variable_sip_call_id")
            print("FREESWIRCH calling... uuid:%s session_id:%s direction:%s call-id:%s" % (uuid, session_id, call_dir, sip_call_id))
        pass

event = MyEvent('10.9.0.115', 8021, 'ClueCon')
timeout = 60
# running 60 seconds on block and then exit. It will never exit if timeout is 0, to return "end" in function channel_event can be stopped
event.run(timeout)
  • mysql
from neko import MySQL
try:
	sql = MySQL('10.9.0.115', 3306, 'sa', '123456', 'mydb')
	# 查询广东省的城市
	result = sql.execute('SELECT id, name, area FROM tb_cities WHERE province="广东"')
	for r in result:
		print(r[0], r[1], r[2])
except Exception as errprint(err)

From the author

Welcome to use pyFneko (●'◡'●)ノ♥
If you find any bug, please report it to me by opening a issue. pyFneko needs to be improved, your contribution will be welcomed.

About

FreeSWITCH工具开发的基础组件

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages