Comments (4)
from scratchattach.
This still don't work (if you check the comment and wonder why it says "reply from python :)" it's just because i replied the root comment as a firts test)
user.reply_comment("reply from python!",
parent_id="340385010", commentee_id="139742995")
from scratchattach.
After testing random stuff i managed to make the reply appear in my messages but nowhere else. Now my code looks like this:
from hugchat import hugchat
from hugchat.login import Login
import scratchattach
import requests
import json
PROMPT = "I want you to act as a scratcher, whenever anyone comments on your profile i will write something like username: comment-content and then you are supposed to write a reply to the comment. Do you understand?"
# Log in to huggingface and grant authorization to huggingchat
EMAIL = ""
PASSWD = ""
# NOTE: trailing slash (/) is required to avoid errors
cookie_path_dir = "./cookies/"
sign = Login(EMAIL, PASSWD)
cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
def chat(input: str):
message_result = chatbot.chat(input)
message_str: str = message_result.wait_until_done()
return message_str
chat(PROMPT)
session = scratchattach.login("banddans-chatbot", "")
user = session.get_linked_user()
last_messages = []
with open("seen_messages.json", "r") as seen_messages_file:
last_messages = json.load(seen_messages_file)
seen_messages_file.close()
while True:
messages = session.messages()
for message in messages:
if message not in last_messages:
print(message)
if message["type"] == "addcomment" and message not in last_messages:
chat_input: str = message["actor_username"] + \
": " + message["comment_fragment"]
to_reply: str = chat(chat_input).split(": ")[-1]
print(to_reply)
print(user.reply_comment(
to_reply, parent_id=message["comment_id"], commentee_id=message["actor_id"]))
last_messages = messages
with open("seen_messages.json", "w") as seen_messages_file:
json.dump(last_messages, seen_messages_file)
seen_messages_file.close()
from scratchattach.
Finally found that comment_id wasn't the same as parent_id. I made this function if anyone ever gets the same issue:
from bs4 import BeautifulSoup
import requests
def find_parent_id(comment_id):
try:
i = 0
while True:
data = requests.get(
"https://scratch.mit.edu/site-api/comments/user/banddans-chatbot/?page=" + str(i)).text
soup = BeautifulSoup(data, features="html.parser")
comment = soup.find(id="comments-" + str(comment_id))
if comment != None:
return comment.parent.parent.parent.find(class_="comment")["data-comment-id"]
break
i += 1
except AttributeError:
return comment_id
from scratchattach.
Related Issues (20)
- How to check if user exists? HOT 2
- Weird error??? HOT 1
- How do i get a Project from a list of them? HOT 5
- How do i sign in with an incorrect password, and make the program know that something is incorrect without crashing HOT 2
- Make api request functions unlimited #206 HOT 3
- Implement a Proper Way to Check “New Scratcher” Status HOT 8
- Implement a Way to Check Account Status HOT 2
- (upcoming update) Enhance cloud requests by replacing busy-sleep event loop HOT 6
- Scratch project response list is randomly (at least seems like randomly) displaying "Error: Check the Python console" HOT 4
- How do you create a request in the python code HOT 3
- 'User' object has no attribute 'is_new_scratcher' HOT 2
- Bug in the function of obtaining cloud variables HOT 1
- How do/can I package a scratchattach project using the turbowarp packager? HOT 2
- SESSION IDS EXPIRED HOT 2
- Why events.user reports None while logged in? HOT 5
- Set varibles in multiple ones without a request HOT 2
- I need [ , ] , { and } characters HOT 7
- The TwCloudConnection.set_var() function is not setting cloud variables. HOT 2
- Add way to get parent_id for profile comments HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scratchattach.