Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "firefox",
"request": "launch",
"reAttach": true,
"name": "Launch index.html",
"file": "${workspaceFolder}/index.html"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
Binary file modified projectEnv/__pycache__/app.cpython-311.pyc
Binary file not shown.
Binary file modified projectEnv/__pycache__/search.cpython-310.pyc
Binary file not shown.
Binary file modified projectEnv/__pycache__/search.cpython-311.pyc
Binary file not shown.
Binary file modified projectEnv/__pycache__/searchCode.cpython-311.pyc
Binary file not shown.
6 changes: 0 additions & 6 deletions projectEnv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,3 @@ def loading():
session['form_data'] = request.form

return render_template("loading.html", gifList=gifList)






Binary file not shown.
Binary file modified projectEnv/instance/posts.db
Binary file not shown.
26 changes: 26 additions & 0 deletions projectEnv/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import re
import praw
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

def sentiment_scores(comment_body):
Expand All @@ -15,6 +18,29 @@ def sentiment_scores(comment_body):
else:
return 0 #neutral

def regbot(comment_body):
score = 0
good_patt = re.compile(r'gl|good|\.*\sW\.*\s+|fire', re.IGNORECASE)
bad_patt = re.compile(r'rl|\sbad|\soff|return', re.IGNORECASE)
good = good_patt.findall(comment_body)
bad = bad_patt.findall(comment_body)
good_score = len(good)
bad_score = len(bad)
score = good_score + bad_score
score = good_score - bad_score
return(score)

def linreg(submission):
# creates score for a post based on the linear relation
# between the comments and the average number of upvotes for a QC post
sd = 28.6
m = 2.59
int = 5.85
c = m * submission.score + int
return(c/sd)






27 changes: 18 additions & 9 deletions projectEnv/searchCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,33 @@ def get_data_if_exist(p_key):
def sortRating(s):
return s.rating

def getRating(comments):
def getRating(prpost):
rating = 0
comments.replace_more(limit=None) #replace all unloaded comment obj with loaded comments
for comment in comments:
rating += sentiment_scores(comment.body)
sentrating = 0
sentnum = 0
prpost.comments.replace_more(limit=None) #replace all unloaded comment obj with loaded comments
# rating from the comment lin reg
baserate = linreg(prpost)
for comment in prpost.comments:
sentrating += sentiment_scores(comment.body)
sentnum = sentnum + 1
rating = baserate * (1 + (sentrating / sentnum))
return rating



def addToPosts(p_data):
#look for cached data
cached= True
rating = get_data_if_exist(p_data.id)
if rating == False:
print("getting ratings", p_data.id)
rating = getRating(p_data.comments)
rating = getRating(p_data)
cached = False
print("not cached")
#add to processed post
print("not cached")
#add to processed post

post_list.append(post("https://www.reddit.com"+ p_data.permalink,
rating,
Expand All @@ -67,9 +78,7 @@ def addToPosts(p_data):

def searchItem(db,prompt):



#purge old processed_ids and posts
# purge old processed_ids and posts

post_list.clear()
total_post_list.clear()
Expand Down Expand Up @@ -98,4 +107,4 @@ def loadMore():


post_list.sort(key=sortRating, reverse = True)#sort the post obj in order of rating
return post_list
return post_list
40 changes: 40 additions & 0 deletions projectEnv/searching.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
library(car)
library(RedditExtractoR)
library(tidyverse)


sexbot <- function(comment_body) {
good_patt <- "gl|good|\\.*\\sW\\.*\\s+|fire"
bad_patt <- "rl|\\sbad|\\soff|return"

good <- str_count(comment_body, regex(good_patt, ignore_case = TRUE))
bad <- str_count(comment_body, regex(bad_patt, ignore_case = TRUE))

score <- good - bad
return(score)
}

prompt <- "QC"
subreddit <- "FashionReps"
time_filter <- "year" # For RedditExtractoR, this will be either "all" or "day"

# Fetch posts
posts <- find_thread_urls(subreddit, keywords = prompt, sort_by = "relevance", period = time_filter)
post_content <- get_thread_content(posts$url)
threads <- post_content$threads
comments <- post_content$comments

# Compute averages
average_upvotes <- mean(threads$score)
average_comments <- mean(posts$num_comments)

# linear reg
comxup <- lm(threads$upvotes ~ threads$comments)
summary(comxup)




# Print results
print(paste("Average number of upvotes for posts: ", average_upvotes))
print(paste("Average number of comments for posts: ", average_comments))
39 changes: 39 additions & 0 deletions projectEnv/stattime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# attempting to explore the relationship between the average special char score and the number of upvotes
from search import sexbot
from searchCode import *
import praw


r = praw.Reddit(
client_id='jknOULmDh_Xkmi5xLSpl_A',
client_secret='5jOGVzfdgGJgRrxS7oPZAzaBZnndEA',
user_agent="smol man",
)

plist = []
listyy = []
prompt = "QC"

for i in r.subreddit("FashionReps").search(query=prompt,
sort="relevance",
limit=100,
time_filter= "year"):
plist.append((i.score, i.num_comments))
listyy.append(getRating(i.comments))


print(len(plist))
# all the averaged values for 100 post
average_upvotes = sum(upvotes for upvotes, _ in plist) / len(plist)
average_comments = sum(comments for _, comments in plist) / len(plist)
average_score = sum(listyy) / len(listyy)



print(f"average score is {average_score}")
print(f"Average number of upvotes for posts with '{len(plist)}' posts: {average_upvotes}")
print(f"Average number of comments for posts with '{len(plist)}' posts: {average_comments}")




38 changes: 38 additions & 0 deletions projectEnv/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import praw
from praw.models import MoreComments
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
from praw.models.util import stream_generator
from searchCode import *
from search import *



def searchItems(prompt):

# purge old processed_ids and posts

post_list.clear()
total_post_list.clear()
#grabs posts based on prompt
for i in r.subreddit("FashionReps").search(query=prompt,
sort="relevance",
limit=24,
time_filter= "year"):
total_post_list.append(i)
#add first 6 posts
print("looked for posts")
return total_post_list

postslst = searchItems(prompt='bapesta QC')
for sub in postslst[:6]:
print(linreg(sub))

print(postslst[3].score)
print(postslst[3].num_comments)

rating = 0
for comment in postslst[3].comments:
rating += sentiment_scores(comment.body)

print(rating)
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,4 @@ def score_valence(self, sentiments, text):
str(vs['compound']), translator_name))
print("----------------------------------------------------")

print("\n\n Demo Done!")
print("\n\n Demo Done!")
Loading