File: sqlite3_process_text.py

package info (click to toggle)
gtk-meshtastic-client 1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,040 kB
  • sloc: python: 4,759; xml: 58; makefile: 3
file content (108 lines) | stat: -rw-r--r-- 3,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import meshtastic.serial_interface
from pubsub import pub
from meshtastic.protobuf import mesh_pb2, storeforward_pb2, paxcount_pb2
from meshtastic import BROADCAST_NUM
import time
import sys
import signal
import sqlite3
import os
from enum import Enum
from gi.repository import GLib
from datetime import datetime, timezone

meshtastic_config_dir = GLib.get_user_config_dir() + '/gtk_meshtastic_client'
version = 0

LongFast_channel_id = '399df22f29297e5dd9b23d8ddc229bb6e64f2d05365b5a478cf6527dc302652c'
limit = 3
offset = 0

def idToHex(nodeId):
    return '!' + hex(nodeId)[2:]

def onDisconnection(interface):
    #there's no need to close a connection once disconnected
    print("Awknowledged disconnection")

def onConnection(interface):
    print("Awknowledged connection")

def onReceive(packet, interface):
    print("Got packet")


# You need to close any active connections if you exit
# If you don't, the interface will continue to be active
# and any stored messages will stay stored on the device
# and will be sent on the stale connection
def signal_handler(sig, frame):
    print("closing")
    interface.close()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)
pub.subscribe(onReceive, 'meshtastic.receive')
pub.subscribe(onDisconnection, 'meshtastic.connection.lost')
pub.subscribe(onConnection, 'meshtastic.connection.established')
interface = meshtastic.serial_interface.SerialInterface()

node_id = idToHex(interface.myInfo.my_node_num)
database_name = meshtastic_config_dir + '/' + node_id + '_messages_v' + str(version) + '.db'
print(database_name)

if not os.path.exists(database_name):
    print("Cannot Find database")
    interface.close()
    sys.exit(0)


con = sqlite3.connect(database_name)
cur = con.cursor()


#Order test messages by time
#for row in cur.execute("SELECT * FROM text_messages ORDER BY time"):
#    print(row)

#find number of entries
res = cur.execute("SELECT COUNT(*) FROM text_messages")
count_list = res.fetchone()
print(count_list[0])

"""
#Print all the rows in the test message table
for row in cur.execute("SELECT * FROM text_messages"):
    print(row)

#DESC orders by latest time
for row in cur.execute("SELECT * FROM text_messages ORDER BY time DESC"):
    print(row)

#Limit 3 entries
for row in cur.execute("SELECT * FROM text_messages ORDER BY time DESC LIMIT 3"):
    print(row)
    #Table text_messages(msg_id, from_id, from_short_name, from_long_name, to_id, direction, text, time, delivered, channel_title)
    #print Msg_id
    print(row[0])
    #print from_long_name
    print(row[3])

#Limit 3, but skip the first 3 entries (so if you previously did limit 3, this gets the next 3)
for row in cur.execute("SELECT * FROM text_messages ORDER BY time DESC LIMIT 3 OFFSET 3"):
    print(row)

#make channel_if, limit, and offset variables you can imclude
for row in cur.execute("SELECT * FROM text_messages WHERE channel_title = ? ORDER BY time DESC LIMIT ? OFFSET ?", (LongFast_channel_id, limit, offset, )):
    print(row)
"""

con.commit()
cur.close()
con.close()
interface.close()
sys.exit(0)


while True:
    time.sleep(1)