Browse Source

Added plain-text output functionality.

master
= 1 month ago
parent
commit
05121f3386
5 changed files with 29 additions and 8 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -3
      README.md
  3. +10
    -0
      scraper/createOutput/plainTextConvert.py
  4. +0
    -1
      scraper/createOutput/textConvert.py
  5. +17
    -4
      scraper/prepOutput.py

+ 1
- 0
.gitignore View File

@@ -1,3 +1,4 @@
/scraper/__pycache__
/scraper/createOutput/__pycache__
*.json
*.txt

+ 1
- 3
README.md View File

@@ -10,7 +10,7 @@ This program allows users to filter by:
- specific rating
- weighted score (positive ratgins have positive values, negative ratings have negative values)

In its current state, this program outputs its findings via either JSON or text file.
The program outputs its findings via either JSON, text file, or plain text.

Examples:

@@ -94,7 +94,5 @@ File saved to path\to\directory\filename.json
## Upcoming
- I plan on implementing functionality to allow for formated text output to be included. This will include special markings for quotes, media, and other special content that would exist within a post. Currently this is left blank in the JSON output.

- I plan on adding copy/paste as an output option.

## Contributing
Pull requests are welcome. I'm always open to new ideas.

+ 10
- 0
scraper/createOutput/plainTextConvert.py View File

@@ -0,0 +1,10 @@
#class for creating plain-text output to user

#format is the same as text-file output

from createOutput import textConvert
from postData import PostData

class PlainTextConvert(textConvert.TextConvert):
def printOutput(self):
print(self.makeTextForOutput())

+ 0
- 1
scraper/createOutput/textConvert.py View File

@@ -59,7 +59,6 @@ text template:

from createOutput import outputPrep
from postData import PostData
import json

class TextConvert(outputPrep.outputPrep):
def makeTextForOutput(self):


+ 17
- 4
scraper/prepOutput.py View File

@@ -2,6 +2,7 @@

from createOutput.jsonConvert import JsonConvert
from createOutput.textConvert import TextConvert
from createOutput.plainTextConvert import PlainTextConvert
from postData import PostData
import os

@@ -56,7 +57,8 @@ def getDirectory(extension):

def createText(posts, toFile):
#creates text file or prints out data
#returns true if file successfully created, false if not
#returns true if file successfully created or data successfully printed
#returns false if file could not be created or user decides agains plain-text output
#
#posts = list of PostData objects
#toFile = True if output being saved to file, False if being printed for copy/paste output
@@ -97,8 +99,19 @@ What would you like to do?
return True

else:#print for copy/pasting
#TODO: add copy/paste functionality
else:#create plain text output
print("Are you sure you want to do this? This is not recommended if you have a lot of posts. (y/n)")
answer = input(": ")
while not (answer.lower() == 'y' or answer.lower() == 'n'):
print("Answer should be 'y' or 'n'. Try again.")
answer = input(": ")
if answer == 'n':
return False
textOut = PlainTextConvert()
for post in posts:
textOut.unpackPostData(post)
textOut.printOutput()
return True


@@ -156,7 +169,7 @@ How would you like your data outputed?

(1) JSON
(2) Text File
(3) Copy/Paste
(3) Plain Text
""")
ui = input(": ")
while not ui.isdigit() or not (0 < int(ui) < 4):


Loading…
Cancel
Save