Skip to content

Commit

Permalink
refactored to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RestfulLeo23 committed Jan 25, 2021
1 parent 5eea26f commit c5825d0
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode/settings.json
__pycache__/data.cpython-39.pyc
.vscode/.ropeproject/objectdb
114 changes: 114 additions & 0 deletions .vscode/.ropeproject/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# The default ``config.py``
# flake8: noqa


def set_prefs(prefs):
"""This function is called before opening the project"""

# Specify which files and folders to ignore in the project.
# Changes to ignored resources are not added to the history and
# VCSs. Also they are not returned in `Project.get_files()`.
# Note that ``?`` and ``*`` match all characters but slashes.
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
# '.svn': matches 'pkg/.svn' and all of its children
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject',
'.hg', '.svn', '_svn', '.git', '.tox']

# Specifies which files should be considered python files. It is
# useful when you have scripts inside your project. Only files
# ending with ``.py`` are considered to be python files by
# default.
# prefs['python_files'] = ['*.py']

# Custom source folders: By default rope searches the project
# for finding source folders (folders that should be searched
# for finding modules). You can add paths to that list. Note
# that rope guesses project source folders correctly most of the
# time; use this if you have any problems.
# The folders should be relative to project root and use '/' for
# separating folders regardless of the platform rope is running on.
# 'src/my_source_folder' for instance.
# prefs.add('source_folders', 'src')

# You can extend python path for looking up modules
# prefs.add('python_path', '~/python/')

# Should rope save object information or not.
prefs['save_objectdb'] = True
prefs['compress_objectdb'] = False

# If `True`, rope analyzes each module when it is being saved.
prefs['automatic_soa'] = True
# The depth of calls to follow in static object analysis
prefs['soa_followed_calls'] = 0

# If `False` when running modules or unit tests "dynamic object
# analysis" is turned off. This makes them much faster.
prefs['perform_doa'] = True

# Rope can check the validity of its object DB when running.
prefs['validate_objectdb'] = True

# How many undos to hold?
prefs['max_history_items'] = 32

# Shows whether to save history across sessions.
prefs['save_history'] = True
prefs['compress_history'] = False

# Set the number spaces used for indenting. According to
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
# unit-tests use 4 spaces it is more reliable, too.
prefs['indent_size'] = 4

# Builtin and c-extension modules that are allowed to be imported
# and inspected by rope.
prefs['extension_modules'] = []

# Add all standard c-extensions to extension_modules list.
prefs['import_dynload_stdmods'] = True

# If `True` modules with syntax errors are considered to be empty.
# The default value is `False`; When `False` syntax errors raise
# `rope.base.exceptions.ModuleSyntaxError` exception.
prefs['ignore_syntax_errors'] = False

# If `True`, rope ignores unresolvable imports. Otherwise, they
# appear in the importing namespace.
prefs['ignore_bad_imports'] = False

# If `True`, rope will insert new module imports as
# `from <package> import <module>` by default.
prefs['prefer_module_from_imports'] = False

# If `True`, rope will transform a comma list of imports into
# multiple separate import statements when organizing
# imports.
prefs['split_imports'] = False

# If `True`, rope will remove all top-level import statements and
# reinsert them at the top of the module when making changes.
prefs['pull_imports_to_top'] = True

# If `True`, rope will sort imports alphabetically by module name instead
# of alphabetically by import statement, with from imports after normal
# imports.
prefs['sort_imports_alphabetically'] = False

# Location of implementation of
# rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general
# case, you don't have to change this value, unless you're an rope expert.
# Change this value to inject you own implementations of interfaces
# listed in module rope.base.oi.type_hinting.providers.interfaces
# For example, you can add you own providers for Django Models, or disable
# the search type-hinting in a class hierarchy, etc.
prefs['type_hinting_factory'] = (
'rope.base.oi.type_hinting.factory.default_type_hinting_factory')


def project_opened(project):
"""This function is called after opening the project"""
# Do whatever you like here!
21 changes: 11 additions & 10 deletions Wallstreetbets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import squarify
from nltk.sentiment.vader import SentimentIntensityAnalyzer


def main():
# set the program parameters
limit = 500 # define the limit
Expand All @@ -30,26 +31,26 @@ def main():
posts, count, c_analyzed, tickers, titles, a_comments = 0, 0, 0, {}, [], {}

start_time = time.time()
reddit = reddit_login()
reddit = reddit_login("Comment Extraction", "cyCpjEI0IKT5HA", "vFo8q24cVc9j8Z7YluYr6zv4Tl0Hmg", "StraightFail815", "$D?x4Um.<r#_@?V")
subreddit = configure_reddit_subreddit(reddit)
hot_python = subreddit.hot() # sorting posts by hot
extract_comments_symbols(hot_python, post_flairs, titles, posts, limit, upvotes, tickers, a_comments, count, c_analyzed)

# sorts the dictionary
symbols = dict(sorted(tickers.items(), key=lambda item: item[1], reverse = True))
top_picks = list(symbols.keys())[0:picks]
time = (time.time() - start_time)
current_time = (time.time() - start_time)

print_results(time, c_analyzed, posts, picks, top_picks, symbols)
print_results(current_time, c_analyzed, posts, picks, top_picks, symbols, titles)
scores = apply_sentiment_analysis(symbols, picks_ayz, a_comments)
print_sentiment_analysis(picks_ayz, scores)

def reddit_login():
return praw.Reddit(user_agent="Comment Extraction",
client_id="cyCpjEI0IKT5HA",
client_secret="vFo8q24cVc9j8Z7YluYr6zv4Tl0Hmg",
username="StraightFail815",
password="$D?x4Um.<r#_@?V")
def reddit_login(user, clientid, clientsecret, usernme, passwrd):
return praw.Reddit(user_agent=user,
client_id=clientid,
client_secret=clientsecret,
username=usernme,
password=passwrd)

def configure_reddit_subreddit(reddit):
return reddit.subreddit('wallstreetbets')
Expand Down Expand Up @@ -81,7 +82,7 @@ def extract_comments_symbols(hot_python, post_flairs, titles, posts, limit, upvo
count += 1


def print_results(time, c_analyzed, posts, picks, top_picks, symbols):
def print_results(time, c_analyzed, posts, picks, top_picks, symbols, titles):
# print top picks
print("It took {t:.2f} seconds to analyze {c} comments in {p} posts.\n".format(t=time, c=c_analyzed, p=posts))
print("Posts analyzed:")
Expand Down

0 comments on commit c5825d0

Please sign in to comment.