Example #1
0
def nat_th(all_ins, nat):
    x, y = -1, -1
    sent2zero = []
    Thread.sleep(10)
    new_data = False
    while True:
        Thread.sleep(1)
        cnt = 0
        for i in range(50):
            if all_ins[i].empty():
                cnt += 1

        data = nat.get()
        cmd, v = data
        if cmd== 'data':
            x, y = v
            pp('Got data', v)
            new_data = True

        if cnt == 50 and new_data:
            sent2zero.append((x, y))
            all_ins[0].put(x)
            all_ins[0].put(y)
            new_data = False
            if len(sent2zero) >= 2 and sent2zero[-2][1] == sent2zero[-1][1]:
                print('TWICE', y)
                exit() # Right answer 16424
Example #2
0
def check(q):
    while True:
        try:
            id = q.get()
            prozy = {'http': proxy.strip(), 'https': proxy.strip()}
            s = requests.session()
            work = False
            s.cookies.clear()
            headers = {
                'User-Agent':
                'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36',
                'Accept-Encoding': 'gzip',
                'Content-Type': 'application/x-www-form-urlencoded'
            }
            r = s.get(
                'http://fitbit.force.com/service/ReplacementOptions?id=5003300{0}nae&l=en_US&replacement=1&voucher=0'
                .format(id),
                verify=False,
                proxies=prozy,
                timeout=12,
                headers=headers)
            if 'Replacement' in r.text:
                f = open('work.txt', 'a')
                f.write(id + "\n")
                f.close()
            if 'Sorry, the server is busy at the moment' in r.text:
                Thread.sleep(1)
        except Exception, e:
            #print e
            pass
Example #3
0
def main():
    blk = '607801'
    a = {
        '0': 'IOP',
        '1': 'IOP',
        '2': 'IOP',
        '3': 'SNRG',
        '4': 'IOP',
        '5': 'IOP',
        '6': 'IOP',
        '7': 'IOP',
        '8': 'IOP',
        '9': 'IOP',
    }
    n = True
    try:
        while n:
            r = requests.get('http://ltc.blockr.io/api/v1/block/info/' + blk,
                             verify=False,
                             proxies=prozy,
                             timeout=12)
        hs = re.findall(',"hash":"(.*?)"', r.text)[0][0]
        if a[hs] is not "":
            n = False
        print a[hs]
        Thread.sleep(0.5)
    except:
        pass
Example #4
0
 def getCurrentPos(self, event):
     global mode
     print('Start to Get mouse pos')
     mode = 4
     Thread.sleep(3000)
     print('Get mouse pos')
     mouse_pos = Env.getMouseLocation()
     print('Current mouse pos: x:' + mouse_pos.x + ' y:' + mouse_pos.y)
import logic as c
from logic import create, delete, read
from threading import Thread
# code is the file name of the file as a library

c.create("Prasanna", 50, 120)
c.read("Prasanna")
c.delete("Prasanna")

tre1 = Thread(target=(create or read or delete),
              args=(key_name, value, timeout))
tre1.start()
tre1.sleep()
tre2 = Thread(target=(create or read or delete),
              args=(key_name, value, timeout))
tre2.start()
tre2.sleep()
x.read("src")
#it returns the value of the respective key in Jasonobject format if the TIME-TO-LIVE IS NOT EXPIRED else it returns an ERROR

x.create("Amrita", 50)
#it returns an ERROR since the key_name already exists in the database
#To overcome this error
#either use modify operation to change the value of a key
#or use delete operation and recreate it

x.modify("Amrita", 55)
#it replaces the initial value of the respective key with new value

x.delete("Amrita")
#it deletes the respective key and its value from the database(memory is also freed)

#we can access these using multiple threads like
t1 = Thread(target=(create or read or delete),
            args=(key_name, value, timeout))  #as per the operation
t1.start()
t1.sleep()
t2 = Thread(target=(create or read or delete),
            args=(key_name, value, timeout))  #as per the operation
t2.start()
t2.sleep()
#and so on upto tn

#the code also returns other errors like
#"invalidkey" if key_length is greater than 32 or key_name contains any numeric,special characters etc.,
#"key doesnot exist" if key_name was mis-spelt or deleted earlier
#"File memory limit reached" if file memory exceeds 1GB
 def run(self):
     """ generated source for method run """
     s = File.separator
     myTempFolder = self.app.tempFolder + s + self.dmsId()
     myAppFolder = self.app.appFolder + s + self.dmsId()
     openDir = File(myTempFolder + s + "open_" + self.userId())
     name = str()
     newName = str()
     baseName = str()
     ext = str()
     newExt = str()
     itemId = str()
     currentMd5 = str()
     cacheMd5 = str()
     n = str()
     uploadContentType = ""
     storedMtime = long()
     currentMtime = long()
     file_ = File()
     dir = File()
     tmp = File()
     tmp2 = File()
     delta = File()
     upload = None
     files = []
     in_ = FileInputStream()
     out = FileOutputStream()
     uploadSuccess = bool()
     uploadRet = HashMap()
     uploadErrorCount = 0
     tmpFileSize = long()
     if not openDir.isDirectory():
         return
     while True:
         try:
             Thread.sleep(1000)
         except InterruptedException as e:
             Thread.currentThread().interrupt()
             return
         if openDir.isDirectory() == False:
             continue 
         files = openDir.listFiles()
         while len(files):
             dir = files[i]
             if dir.isDirectory():
                 itemId = dir.__name__
                 newName = ""
                 newExt = ""
                 #  load info
                 if openInfo == None or openInfo.isEmpty():
                     if dir.lastModified() < System.currentTimeMillis() - 1000 * 60 * 60:
                         print "no open file info found for " + itemId
                         self.app.deleteOpenItem(itemId)
                         if dir.exists():
                             dir.setLastModified(System.currentTimeMillis())
                     continue 
                 if cacheInfo == None or cacheInfo.isEmpty():
                     print "no cache info found for " + itemId
                     self.app.deleteOpenItem(itemId)
                     continue 
                 storedMtime = Long.parseLong(openInfo.get("mtime") + "")
                 name = str(openInfo.get("name"))
                 baseName = name.substring(0, name.lastIndexOf(".")) if name.lastIndexOf(".") > -1 else name
                 ext = name.substring(name.lastIndexOf(".") + 1, len(name)) if name.lastIndexOf(".") > -1 else ""
                 file_ = File(myTempFolder + s + "open_" + self.userId() + s + itemId + s + name)
                 if not ext == "" and File(file_.getAbsolutePath() + "x").exists():
                     #  file name has changed to docx, xlsx, enz
                     newName = name + "x"
                     newExt = newName.substring(newName.lastIndexOf(".") + 1, len(newName))
                 if not newExt == "" and not newExt == ext and (not openInfo.containsKey("readOnly") or not openInfo.get("readOnly") == "true"):
                     #  file extension has changed on writable document
                     self.app.getTransponderLine("action=alterItemExtension&itemId=" + itemId + "&ext=" + newExt)
                 if not newName == "" and not newName == name:
                     #  name has changed
                     openInfo.put("name", newName)
                     FileActions.saveHashMap(openInfo, myTempFolder + s + "open_" + self.userId() + s + itemId + ".json")
                     file_ = File(myTempFolder + s + "open_" + self.userId() + s + itemId + s + newName)
                     name = newName
                 if not file_.exists():
                     continue 
                 if not openInfo.containsKey("readOnly") or not openInfo.get("readOnly") == "true":
                     #  lock or refresh lock if autoLocking is on and item is not read-only
                     if openInfo.containsKey("expectFileLock") and not openInfo.get("expectFileLock") == "no":
                         fileIsLocked = FileActions.isLockedByFileSystem(file_) if openInfo.get("expectFileLock") == "fileSystem" else FileActions.isLockedByTmpFile(file_)
                         #  files that are locked by the client when opened
                         if fileIsLocked and (lock == None or not lock.containsKey("userId") or not lock.get("userId") == self.userId() or Long.parseLong(lock.get("stamp") + "") < System.currentTimeMillis() - 4 * 60 * 1000):
                             #  lock item if not locked or not locked by me or lock is old
                             self.app.lockItem(itemId)
                         elif not fileIsLocked and lock != None and lock.containsKey("userId") and lock.get("userId") == self.userId():
                             #  unlock if file is not locked and current lock is mine
                             self.app.unlockItem(itemId)
                             deleteItem = True
                     elif (not openInfo.containsKey("expectFileLock") or not openInfo.get("expectFileLock") == "tmpFile") and FileActions.isLockedByTmpFile(file_):
                         print "update track file locking by temp file"
                         openInfo.put("expectFileLock", "tmpFile")
                         FileActions.saveHashMap(openInfo, myTempFolder + s + "open_" + self.userId() + s + itemId + ".json")
                 if openInfo.containsKey("readOnly") and openInfo.get("readOnly") == "true" and openInfo.containsKey("expectFileLock") and not openInfo.get("expectFileLock") == "no":
                     #  read only docs can alsow be deleted when lock is lifted
                     fileIsLocked = FileActions.isLockedByFileSystem(file_) if openInfo.get("expectFileLock") == "fileSystem" else FileActions.isLockedByTmpFile(file_)
                     if not fileIsLocked:
                         deleteItem = True
                 #  check if file is changed
                 currentMtime = file_.lastModified()
                 if file_.exists() and currentMtime > storedMtime:
                     try:
                         #  check if file is in rest
                         tmpFileSize = len(file_)
                         Thread.sleep(200)
                         if tmpFileSize == len(file_) and file_.lastModified() == currentMtime:
                             #  copy current file
                             tmp = FileActions.copy(file_)
                             currentMd5 = FileActions.MD5(tmp)
                             cacheMd5 = str(cacheInfo.get("md5"))
                             if not currentMd5 == cacheMd5:
                                 #  file change found
                                 if openInfo.containsKey("readOnly") and openInfo.get("readOnly") == "true":
                                     #  read only
                                     self.app.evalJs("window['" + self.app.jsObj + "'].notifieReadOnlyFileChange(" + itemId + " , '" + cacheInfo.get("name") + "')")
                                     self.app.getTransponderLine("action=notifyEditOnReadOnly&itemId=" + itemId)
                                     #  update open info
                                     # openInfo.put("md5", currentMd5);
                                     openInfo.put("mtime", currentMtime + "")
                                     FileActions.saveHashMap(openInfo, myTempFolder + s + "open_" + self.userId() + s + itemId + ".json")
                                 else:
                                     #  save change
                                     uploadSuccess = False
                                     self.app.saving = True
                                     self.app.resetProgress()
                                     if self.app.language == "nl":
                                         self.app.progressDescription = "upload veranderingen in " + cacheInfo.get("name")
                                     else:
                                         self.app.progressDescription = "uploading changes in " + cacheInfo.get("name")
                                     self.app.evalJs("window['" + self.app.jsObj + "'].notifieAutoUploadStart(" + itemId + " , '" + cacheInfo.get("name").__str__().replaceAll("'", "") + "')")
                                     if not uploadSuccess:
                                         n = file_.__name__
                                         if 1024 < len(tmp) or n.endsWith(".zip") or n.endsWith(".gz") or n.endsWith(".rar") or n.endsWith(".jar") or n.endsWith(".bz2") or n.endsWith(".gif") or n.endsWith(".png") or n.endsWith(".jpg") or n.endsWith(".jpeg") or n.endsWith(".tif") or n.endsWith(".tiff") or n.endsWith(".psd") or n.endsWith(".ai") or n.endsWith(".gz") or n.endsWith(".tgz") or n.endsWith(".mp3") or n.endsWith(".mpeg") or n.endsWith(".wav") or n.endsWith(".mp4") or n.endsWith(".m4a") or n.endsWith(".m4p") or n.endsWith(".avi") or n.endsWith(".fla") or n.endsWith(".flv") or n.endsWith(".exe") or n.endsWith(".xlsx") or n.endsWith(".docx") or n.endsWith(".pptx") or n.endsWith(".wma") or n.endsWith(".wmv"):
                                             upload = tmp
                                             uploadContentType = ""
                                         else:
                                             upload = FileActions.gzip(tmp)
                                             uploadContentType = "gzip"
                                         self.app.cancel = False
                                         self.app.progressDone = 0
                                         self.app.progressTotal = float(len(upload)) / 1024
                                         if uploadContentType == "gzip":
                                             print "upload gzip for " + file_.__name__ + " - " + OfficeDrive_SE6.bitesToStr(len(upload)) + " = " + Math.round(float(len(upload)) / len(tmp) * 100) + "% of origional..."
                                         else:
                                             print "upload " + file_.__name__ + " - " + OfficeDrive_SE6.bitesToStr(len(upload)) + "..."
                                         if self.app.language == "nl":
                                             self.app.progressDescription = "upload " + cacheInfo.get("name")
                                         else:
                                             self.app.progressDescription = "uploading " + cacheInfo.get("name")
                                         uploadSuccess = self.app.doFilePut(upload, self.app.transponderUrl() + "?holder-type=java&sid=" + self.app.sid() + "&dmsId=" + self.dmsId() + "&action=updateItem&userMethod=autosave&itemId=" + itemId + "&contentType=" + uploadContentType + "&sourceMd5=" + cacheMd5 + "&targetMd5=" + currentMd5)
                                         if not uploadSuccess and uploadRet.get("status") == "canceled":
                                             if tmp.exists():
                                                 tmp.delete()
                                             if upload.exists():
                                                 upload.delete()
                                             print "       > canceled"
                                             print "cancel auto save"
                                             openInfo.put("md5", currentMd5)
                                             openInfo.put("mtime", currentMtime + "")
                                             FileActions.saveHashMap(openInfo, myTempFolder + s + "open_" + self.userId() + s + itemId + ".json")
                                             continue 
                                     if not uploadSuccess:
                                         if tmp.exists():
                                             tmp.delete()
                                         if upload.exists():
                                             upload.delete()
                                         uploadErrorCount += 1
                                         if uploadErrorCount > 2:
                                             print "        > failed and quitting"
                                             self.app.evalJs("window['" + self.app.jsObj + "'].notifieAutoUploadEnd(false)")
                                             self.app.progressDescription = "failed"
                                             System.exit(1)
                                         else:
                                             print "        > failed and retrying"
                                             Thread.sleep(2 * 1000)
                                     else:
                                         uploadErrorCount = 0
                                         print "        > completed"
                                         if Math.round(self.app.progressDone) < 1:
                                             self.app.progressTotal = self.app.progressDone = 1
                                         if self.app.language == "nl":
                                             self.app.progressDescription = "gereed"
                                         else:
                                             self.app.progressDescription = "done"
                                         self.app.evalJs("window['" + self.app.jsObj + "'].notifieAutoUploadEnd(true)")
                                         if self.app.maxEncryptionFileSize < len(tmp):
                                             cacheInfo.put("encrypted", "true")
                                             self.app.encrypter().encrypt(tmp, File(myAppFolder + s + "cache" + s + itemId))
                                             tmp.delete()
                                         else:
                                             cacheInfo.put("encrypted", "false")
                                             FileActions.move(tmp, File(myAppFolder + s + "cache" + s + itemId))
                                         cacheInfo.put("md5", currentMd5)
                                         cacheInfo.put("mtime", currentMtime + "")
                                         if not newExt == "" and cacheInfo.containsKey("name"):
                                             cacheInfo.put("name", cacheInfo.get("name").__str__().substring(0, cacheInfo.get("name").__str__().lastIndexOf(".")) + "." + newExt)
                                         FileActions.saveHashMap(cacheInfo, myAppFolder + s + "cache" + s + itemId + ".json")
                                         openInfo.put("md5", currentMd5)
                                         openInfo.put("mtime", currentMtime + "")
                                         FileActions.saveHashMap(openInfo, myTempFolder + s + "open_" + self.userId() + s + itemId + ".json")
                                         if upload.exists():
                                             upload.delete()
                                     self.app.saving = False
                             else:
                                 openInfo.put("mtime", currentMtime + "")
                                 FileActions.saveHashMap(openInfo, myTempFolder + s + "open_" + self.userId() + s + itemId + ".json")
                                 tmp.delete()
                     except Exception as e:
                         print e.getMessage()
                 if deleteItem:
                     self.app.deleteOpenItem(itemId)
             i += 1