python - python 正则表达式帮助未知,直到**自我解决**
问题描述
如果找到匹配项,我正在尝试打印一条特殊行,这就是我到目前为止所拥有的。我将数据写入文件并显示,所以我可以看到过去发生了什么。我想获取正则表达式匹配的整行数据,只需添加波段,这是从文件中读取的数据
DX de SP5FHF/ 7022.0 SP5FHF/5 SPFF0607
0917Z
DX de F4HUN: 7144.0 F2YT/P FFF-0686 73S PAUL
0917Z
代码文本
#!/usr/bin/env python
import re
import telnetlib
import time
HOST = "xxxxxxx"
PORT = 0000
user = "xxxxxx"
tn = telnetlib.Telnet(HOST,PORT)
tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
count = 0
timer = 0
print("Welcome to the KM4OUS Cluster Connector")
while (count < 1):
f = open("/home/w33ds/cluster.csv", "w")
push = tn.read_very_eager()
f.write(push.encode('utf-8'))
#print(push)
f.close()
f = open('/home/w33ds/cluster.csv','r')
regex = re.compile(r'(DX de .+\s142[2-9].+Z\s\w\w\w\w)|(DX de .+\s143[0-5].+Z\s\w\w\w\w)')
for x in f:
twenty = regex.findall(x)
for band in twenty:
band = re.sub('\'|\,|\(|\)','', str(band))
print(band)," 20M SSB"
f.close()
tcw = open('/home/w33ds/cluster.csv','r')
regex = re.compile(r'(DX de .+\s140[2-9].Z\s\w\w\w\w)')
for t in tcw:
twentyc = regex.findall(t)
for bandtc in twentyc:
bandtc = re.sub('\'|\,|\(|\)','', str(bandtc))
print(bandtc)," 20M CW DIGI"
tcw.close()
g = open('/home/w33ds/cluster.csv','r')
regex = re.compile(r'(DX de .+\s717[8-9].Z\s\w\w\w\w)|(DX de .+\s72[0-9].Z\s\w\w\w\w)|(DX de .+\s718.Z\s\w\w\w\w)')
for y in g:
forty = regex.findall(y)
for bandb in forty:
bandb = re.sub('\'|\,|\(|\)','', str(bandb))
print(bandb)," 40M SSB"
g.close()
cw = open('/home/w33ds/cluster.csv','r')
regex = re.compile(r'(DX de .+\s70[2-9].+Z\s\w\w\w\w)')
for z in cw:
fortyc = regex.findall(z)
for bandc in fortyc:
bandc = re.sub('\'|\,|\(|\)','', str(bandc))
print(bandc)," 40M CW DIGI"
time.sleep(5)
if timer == 30:
print (time.ctime() + "\nKM4OUS CLuster Connector")
cw.close()
count = 0
timer = timer+1
我想将整行拉到代码的频率范围内。
解决方案
推荐阅读
- c# - 为什么我的请求在尝试通过电子邮件获取用户时挂起
- node.js - 如何从 Node/Express 中的 Axios GET 请求中读取和解析 CSV 文件?
- python - 无法使用 Python 中的套接字将不同目录的文件上传到服务器
- networking - 如何强制 UDP 数据包通过 TCP 封装以进行云游戏?(VPN TCP 隧道,丢包修复)
- neoload - 如何在docker中部署neoload
- java - 在 Java 多线程中管理资源
- c - 为什么 fgetc 返回 ffffffff 而不是文件中的实际数据?
- azure - 存储可以从中间播放的视频
- wordpress - 使用简码加载的 elementor 页面没有 CSS 类
- csv - Highcharts 将键定义的列从导出到 CSV 中删除