(fileName, fileData)
| 601 | main() |
| 602 | |
| 603 | def saveFile(fileName, fileData): #Allows attachments and messages/broadcats to be saved |
| 604 | |
| 605 | #This section finds all invalid characters and replaces them with ~ |
| 606 | fileName = fileName.replace(" ", "") |
| 607 | fileName = fileName.replace("/", "~") |
| 608 | #fileName = fileName.replace("\\", "~") How do I get this to work...? |
| 609 | fileName = fileName.replace(":", "~") |
| 610 | fileName = fileName.replace("*", "~") |
| 611 | fileName = fileName.replace("?", "~") |
| 612 | fileName = fileName.replace('"', "~") |
| 613 | fileName = fileName.replace("<", "~") |
| 614 | fileName = fileName.replace(">", "~") |
| 615 | fileName = fileName.replace("|", "~") |
| 616 | |
| 617 | directory = 'attachments' |
| 618 | |
| 619 | if not os.path.exists(directory): |
| 620 | os.makedirs(directory) |
| 621 | |
| 622 | filePath = directory +'/'+ fileName |
| 623 | |
| 624 | '''try: #Checks if file already exists |
| 625 | with open(filePath): |
| 626 | print 'File Already Exists' |
| 627 | return |
| 628 | except IOError: pass''' |
| 629 | |
| 630 | |
| 631 | f = open(filePath, 'wb+') #Begin saving to file |
| 632 | f.write(fileData.decode("base64")) |
| 633 | f.close |
| 634 | |
| 635 | print '\n Successfully saved '+ filePath + '\n' |
| 636 | |
| 637 | def attachment(): #Allows users to attach a file to their message or broadcast |
| 638 | theAttachmentS = '' |
no test coverage detected