Han-Gang / test

test
0 stars 0 forks source link

多线程 剪贴板监控+多线程处理 multi thread clipboard #45

Open myaws010010 opened 4 years ago

myaws010010 commented 4 years ago
import clipboard
import time
import winsound
import _thread

import re

text = "sdafs"

def print_time( threadName, delay):
    global text
    while 1:
        matchObj = re.search( '([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})', text)
        if matchObj:
            import requests

            url = "https://www.google.com/"+str(threadName)

            querystring = {"parameter1":matchObj.group(0)}

            payload = ""
            headers = {
                'Content-Type': "application/json",
                'cache-control': "no-cache"
                }

            response = requests.request("GET", url, data=payload, headers=headers, params=querystring)

            print(time.time(),response.text[:250])

#   count = 0
#   while count < 5:
#      time.sleep(delay)
#      count += 1
#      print ("%s: %s" % ( threadName, time.ctime(time.time()) ))

try:
   _thread.start_new_thread( print_time, ("abc", 2, ) )
   _thread.start_new_thread( print_time, ("def", 4, ) )
except:
   print ("Error: 无法启动线程")

oldtext = ""

frequency = 2500  # Set Frequency To 2500 Hertz
duration = 600  # Set Duration To 1000 ms == 1 second
while (True):
    time.sleep(0.02)

#clipboard.copy("abc")  # now the clipboard content will be string "abc"
    text = clipboard.paste()  # text will have the content of clipboard
    if text != oldtext:
        winsound.Beep(frequency, duration)
        #try:
        matchObj = re.search( '([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})', text)
        if matchObj:
                        print ("============================",time.time())
                        print (matchObj.group(0))
        #except:
            #print ("UnicodeEncodeError: 'gbk' codec can't encode character")

        oldtext = text

matchObj = re.match( r'([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})', a, re.M|re.I)
myaws010010 commented 4 years ago
import clipboard
import time
import winsound
import _thread

import re

text = "sdafs"

def print_time( threadName, delay):
    global text
    while 1:
        matchObj = re.search( '([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})', text)
        if matchObj:
            import requests

            url = "https://www.google.com/"+str(threadName)

            querystring = {"parameter1":matchObj.group(0)}

            payload = ""
            headers = {
                'Content-Type': "application/json",
                'cache-control': "no-cache"
                }

            response = requests.request("GET", url, data=payload, headers=headers, params=querystring)

            print(time.time(),response.text[:250])

#   count = 0
#   while count < 5:
#      time.sleep(delay)
#      count += 1
#      print ("%s: %s" % ( threadName, time.ctime(time.time()) ))

try:
   _thread.start_new_thread( print_time, ("abc", 2, ) )
   _thread.start_new_thread( print_time, ("def", 4, ) )
except:
   print ("Error: 无法启动线程")

oldtext = ""

frequency = 2500  # Set Frequency To 2500 Hertz
duration = 600  # Set Duration To 1000 ms == 1 second
while (True):
    time.sleep(0.02)

#clipboard.copy("abc")  # now the clipboard content will be string "abc"
    text = clipboard.paste()  # text will have the content of clipboard
    if text != oldtext:
        winsound.Beep(frequency, duration)
        #try:
        matchObj = re.search( '([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})', text)
        if matchObj:
                        print ("============================",time.time())
                        print (matchObj.group(0))
        #except:
            #print ("UnicodeEncodeError: 'gbk' codec can't encode character")

        oldtext = text

#matchObj = re.match( r'([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})', a, re.M|re.I)