gpt4 book ai didi

php - 我需要帮助 python 代码将短信发送到存储在 mysql 数据库中的号码

转载 作者:行者123 更新时间:2023-11-30 00:22:22 24 4
gpt4 key购买 nike

我的数据库中有一个表,其中包含列、部门名称、姓名、ID、日期、日期、时间、手机号码。每列都有自己的值(value)。我想从数据库中获取上述数据并发送一条短信以从数据库表中提取详细信息短信格式为:日期姓名考勤,日期为:时间(发送至数据库中的编号)

我们找到了将短信发送到文本文件的代码,并且通过 sim 300 工作正常。但我们希望它发送到 nos。存储在数据库中我们为文本文件设计的代码如下

import serial
import MySQLdb as mdb
import _mysql as m

def sendMsg(s,num,text):
cr = chr(13)
s.write('at' + cr)
s.write('AT+CMGF=1'+cr)
s.write('AT+CMGS="' + num + '"' + cr)
s.write(text)
s.write(cz)
s.write(cr)
print "Msg Sent"
#print s.readline()
#print s.readline()
#def sendComm(s,string):
# s.write(string + chr(13))
# print s.readline()
# print string,'--->',s.readline()

s = serial.Serial(19)
cz = chr(26)
s.setBaudrate(9600)
with open('palav.txt','r') as f:
lines = f.readlines()
for line in lines:
name,number,att = line.split(',')
att = att.strip()
text = "Your ward %s is having attendance %s%%" % (name,att)
print text
sendMsg(s,number,text)
print "Message Sent"


s.close()

请帮我们通过数据库发送用户名:root,密码:""数据库:参加

最佳答案

#!/usr/bin/python
# view_rows.py - Fetch and display the rows from a MySQL database query
# import the MySQLdb and sys modules
import MySQLdb
import sys



# open a database connection
# be sure to change the host IP address, username, password and database name to match your own
connection = MySQLdb.connect (host = "192.168.1.2", user = "user", passwd = "password, db = "scripting_mysql")
# prepare a cursor object using cursor() method
cursor = connection.cursor ()
# execute the SQL query using execute() method.
cursor.execute ("select mobile_number from table ")
# fetch all of the rows from the query
data = cursor.fetchall ()
# print the rows
for row in data :
print row[0]// this ur mobile no --> add this to ur function send sms

// addd ur function here
# close the cursor object
cursor.close ()
# close the connection
connection.close ()
# exit the program
sys.exit()

关于php - 我需要帮助 python 代码将短信发送到存储在 mysql 数据库中的号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23127013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com