-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
42 lines (30 loc) · 1.13 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import contextlib
import sys
from logging import DEBUG, basicConfig
import pyquickshare
basicConfig(level=DEBUG)
async def send(file: str) -> None:
first = await anext(pyquickshare.discover_services())
return await pyquickshare.send_to(first, file=file)
async def main(argv: list[str]) -> None:
if len(argv) < 2:
print("Usage: example.py <mode> [args...]")
return
if argv[1] == "send":
if len(argv) < 3:
print("Usage: example.py send <file>")
return
await send(argv[2])
elif argv[1] == "receive":
# if you want to appear like different devices, you can change the endpoint_id like this:
# asnyc for request in pyquickshare.receive(endpoint_id=b"1234"):
# (the endpoint_id must be 4 bytes long, you can use pyquickshare.generate_enpoint_id())
async for request in pyquickshare.receive():
results = await request.accept()
print(results)
else:
print("Unknown mode:", argv[1])
if __name__ == "__main__":
with contextlib.suppress(KeyboardInterrupt):
asyncio.run(main(sys.argv))