|
| 1 | +**Scratch API wrapper with support for almost all site features.** Created by [TimMcCool](https://scratch.mit.edu/users/TimMcCool/). |
| 2 | + |
| 3 | +This library can set cloud variables, follow Scratchers, post comments and do so much more! It has special features that make it easy to transmit data through cloud variables. |
| 4 | + |
| 5 | +<p align="left"> |
| 6 | + <img width="120" src="https://github.com/TimMcCool/scratchattach/blob/main/logos/logo.svg"> |
| 7 | +</p> |
| 8 | + |
| 9 | +[](https://pypi.python.org/pypi/scratchattach/) |
| 10 | +[](https://pypi.python.org/pypi/scratchattach/) |
| 11 | +[](https://pypi.python.org/pypi/scratchattach/) |
| 12 | +[](https://github.com/TimMcCool/scratchattach/blob/master/LICENSE) |
| 13 | +[](https://scratchattach.readthedocs.io/en/latest/?badge=latest) |
| 14 | + |
| 15 | +## It is *strongly* advised to learn Python before using scratchattach. |
| 16 | + |
| 17 | +# Documentation |
| 18 | + |
| 19 | +- **[Documentation](https://github.com/TimMcCool/scratchattach/wiki/Documentation)** |
| 20 | + |
| 21 | +- [Cloud Variables](https://github.com/TimMcCool/scratchattach/wiki/Documentation#cloud-variables) |
| 22 | +- [Cloud Requests](https://github.com/TimMcCool/scratchattach/wiki/Cloud-Requests) |
| 23 | +- [Cloud Storage](https://github.com/TimMcCool/scratchattach/wiki/Cloud-Storage) |
| 24 | +- [Filterbot](https://github.com/TimMcCool/scratchattach/wiki/Filterbot) |
| 25 | +- [Self-hosting a TW cloud websocket](https://github.com/TimMcCool/scratchattach/wiki/Documentation#hosting-a-cloud-server) |
| 26 | + |
| 27 | +# Helpful resources |
| 28 | + |
| 29 | +- [Get your session id](https://github.com/TimMcCool/scratchattach/wiki/Get-your-session-id) |
| 30 | + |
| 31 | +- [Examples](https://github.com/TimMcCool/scratchattach/wiki/Examples) |
| 32 | +- [Hosting](https://github.com/TimMcCool/scratchattach/wiki/Hosting) |
| 33 | + |
| 34 | +- [Migrating to v2](https://github.com/TimMcCool/scratchattach/wiki/Migrating-to-v2) |
| 35 | + |
| 36 | +Report bugs by opening an issue on this repository. If you need help or guideance, leave a comment in the [official forum topic](https://scratch.mit.edu/discuss/topic/603418/ |
| 37 | +). Projects made using scratchattach can be added to [this Scratch studio](https://scratch.mit.edu/studios/31478892/). |
| 38 | + |
| 39 | +# Helpful for contributors |
| 40 | + |
| 41 | +- **[Structure of the library](https://github.com/TimMcCool/scratchattach/wiki/Structure-of-the-library)** |
| 42 | + |
| 43 | +- [Extended documentation (WIP)](https://scratchattach.readthedocs.io/en/latest/) |
| 44 | + |
| 45 | +- [Change log](https://github.com/TimMcCool/scratchattach/blob/main/CHANGELOG.md) |
| 46 | + |
| 47 | +Contribute code by opening a pull request on this repository. |
| 48 | + |
| 49 | +# ️Example usage |
| 50 | + |
| 51 | +Set a cloud variable: |
| 52 | + |
| 53 | +```py |
| 54 | +import scratchattach as sa |
| 55 | + |
| 56 | +session = sa.login("username", "password") |
| 57 | +cloud = session.connect_cloud("project_id") |
| 58 | + |
| 59 | +cloud.set_var("variable", value) |
| 60 | +``` |
| 61 | + |
| 62 | +**[More examples](https://github.com/TimMcCool/scratchattach/wiki/Examples)** |
| 63 | + |
| 64 | +# Getting started |
| 65 | + |
| 66 | +**Installation:** |
| 67 | + |
| 68 | +Run the following command in your command prompt / shell: |
| 69 | + |
| 70 | +``` |
| 71 | +pip install -U scratchattach |
| 72 | +``` |
| 73 | + |
| 74 | +If this doesn't work, try running: |
| 75 | +``` |
| 76 | +python -m pip install -U scratchattach |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | +**Logging in with username / password:** |
| 81 | + |
| 82 | +```python |
| 83 | +import scratchattach as sa |
| 84 | + |
| 85 | +session = sa.login("username", "password") |
| 86 | +``` |
| 87 | + |
| 88 | +`login()` returns a `Session` object that saves your login and can be used to connect objects like users, projects, clouds etc. |
| 89 | + |
| 90 | +**Logging in with a sessionId:** *You can get your session id from your browser's cookies. [More information](https://github.com/TimMcCool/scratchattach/wiki/Get-your-session-id)* |
| 91 | +```python |
| 92 | +import scratchattach as sa |
| 93 | + |
| 94 | +session = sa.login_by_id("sessionId", username="username") #The username field is case sensitive |
| 95 | +``` |
| 96 | + |
| 97 | +**Cloud variables:** |
| 98 | + |
| 99 | +```py |
| 100 | +cloud = session.connect_cloud("project_id") # connect to the cloud |
| 101 | + |
| 102 | +value = cloud.get_var("variable") |
| 103 | +cloud.set_var("variable", "value") # the variable name is specified without the cloud emoji |
| 104 | +``` |
| 105 | + |
| 106 | +**Cloud events:** |
| 107 | + |
| 108 | +```py |
| 109 | +cloud = session.connect_cloud('project_id') |
| 110 | +events = cloud.events() |
| 111 | + |
| 112 | +@events.event |
| 113 | +def on_set(activity): |
| 114 | + print("variable", activity.var, "was set to", activity.value) |
| 115 | +events.start() |
| 116 | +``` |
| 117 | + |
| 118 | +**Follow users, love their projects and comment:** |
| 119 | + |
| 120 | +```py |
| 121 | +user = session.connect_user('username') |
| 122 | +user.follow() |
| 123 | + |
| 124 | +project = user.projects()[0] |
| 125 | +project.love() |
| 126 | +project.post_comment('Great project!') |
| 127 | +``` |
| 128 | + |
| 129 | +**All scratchattach features are documented in the [documentation](https://github.com/TimMcCool/scratchattach/wiki/Documentation).** |
0 commit comments