Note that this is Roblox's version of lua.
I want to upload a table to Pastebin. Here is what I have for Pastebin.
h = game:GetService'HttpService'
JSON = h:JSONEncode(ImgScript) --ImgScript is a table formatted like {{x,y,z}, {x,y,z}, {x,y,z}, etc.}
h:PostAsync('http://pastebin.com/api/api_post.php','&api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. JSON)
This doesn't work, and I can't seem to figure out why.
EDIT:
I also tried this and it didn't work.
h = game:GetService'HttpService'
api_params = {
["api_dev_key"] = "CensoredDevKey",
["api_option"] = "paste",
["api_paste_code"] = ImgScript
}
api_params = h:JSONEncode(api_params)
h:PostAsync('http://www.pastebin.com/api/api_post.php', api_params)
EDIT:
I also tried this and it didn't work:
h = game:GetService'HttpService'
JSON = h:JSONEncode(ImgScript) --ImgScript is a table formatted like {{x,y,z}, {x,y,z}, {x,y,z}, etc.}
data = h:UrlEncode('&api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. JSON)
h:PostAsync('http://pastebin.com/api/api_post.php', data)
Try the following:
h = game:GetService'HttpService'
pasteData = h:UrlEncode( h:JSONEncode(ImgScript) )
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. pasteData,
2
)
The last parameter, 2 specifies that the data being sent is Application/Url-Encoded.
I think that this should do the trick. Do inform here if it doesn't.
PS: Where are you receiving the result from this POST request?
So I've finished the code, but sadly, Roblox limits the PostAsync size to 256 bytes so any upload larger than that will be GZIPed (up to 1024kb), which Pastebin doesn't know what to do with.
Anyhow, I've released the code here:
http://www.roblox.com/Pastebin-Upload-item?id=302297532
It is:
--Created by GShocked. PM me if you have questions!
h = game:GetService'HttpService'
api_dev_key = '' --Your Pastebin developer key goes here. Log in first, and then you can find it at pastebin.com/api
api_paste_code = '' --The content of your new paste
api_paste_private = '1' --0 public; 1 unlisted; 2 private
api_paste_name = '' --Name your new paste
api_paste_expire_date = 'N' --N for never expire, 10M for 10 minutes, etc.
api_paste_format = 'lua' --The syntax highlighting
api_user_key = '' --This is generated using the login info
api_paste_name = h:UrlEncode(api_paste_name)
api_paste_code = h:UrlEncode(api_paste_code)
username = '' --Your Pastebin username goes here
password = '' --Your Pastebin password goes here
api_user_key = h:PostAsync(
'http://pastebin.com/api/api_login.php',
'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password,
2
)
print(api_user_key) --DON'T DELETE THIS! IT IS ESSENTIAL FOR THE USER KEY TO BE GENERATED!
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=' .. api_paste_private .. '&api_paste_name=' .. api_paste_name .. '&api_paste_expire_date=' .. api_paste_expire_date .. '&api_paste_format=' .. api_paste_format .. '&api_dev_key=' .. api_dev_key .. '&api_paste_code=' .. api_paste_code,
2
)
Related
I have managed to get the text I want but I can't seem to send the entire list to a telegram message. I only manage to send the first line.
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
driver.get("")
Source = driver.page_source
soup = BeautifulSoup(Source, "html.parser")
for cars in soup.findAll(class_="car-title"):
print(cars.text)
driver.close()
def telegram_bot_sendtext(bot_message):
bot_token = ''
bot_chatID = ''
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
return response.json()
test = telegram_bot_sendtext(cars.text)
The print function gives me this
AUDI E-TRON
MERCEDES-BENZ EQC
TESLA MODEL 3
NISSAN LEAF
MERCEDES-BENZ EQV
AUDI E-TRON
At some point I would like to add a function to check for updates and if there any changes then send a push message to telegram. If someone could point me in the right direction I would be grateful.
What happens?
Your sending one line, cause you do not store the results anywhere and only the last result from iterating is in memory.
How to fix?
Asuming you want to send text as in the question, you should store results in variable - Iterate over resultset, extract text and join() results by newline character:
cars = '\n'.join([cars.text for cars in soup.find_all(class_="car-title")])
Example
...
cars = '\n'.join([cars.text for cars in soup.find_all(class_="car-title")])
def telegram_bot_sendtext(bot_message):
bot_token = ''
bot_chatID = ''
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
return response.json()
test = telegram_bot_sendtext(cars)
I am trying to automate drag and drop between two File Explorers on windows OS. I could find online help to drag and drop implementation for Browsers.
But no help for drag and drop for file to another File Explorer.
Use for this the Shell.Application object. To get the selection from the explorer you can use the following function:
;===============================================================================
; Function Name....: _ActiveExplorer_GetSelected
; Description......: Creates an array with
; - Count of selected files/folder
; - Path of active Explorer window and
; - the path/es of selected file/s /folder
; Requirement(s)...: Opened Explorer window
; Return Value(s)..: Array with data, $a[0] = Count, $a[1] = Folderpath, $a[2..] = File/Foldername
; .................: ATTENTION! Last index $a[0]+1 !!
; Author(s)........: BugFix ( AutoIt#bug-fix.info )
;===============================================================================
Func _ActiveExplorer_GetSelected()
Local $oShell = ObjCreate("Shell.Application")
Local $oExplorer, $sPath, $oFolderView, $iCount = 0, $sSelectedFiles = '', $n = 2
Local $oShellWindows = $oShell.Windows
For $i = 0 To $oShellWindows.Count -1
$oExplorer = $oShellWindows($i)
$sPath = StringReplace(StringReplace(StringTrimLeft($oExplorer.LocationURL, 8), '%20', ' '), '/', '\')
If WinGetTitle('[ACTIVE]') = $sPath Then ExitLoop
Next
$oFolderView = $oExplorer.Document.SelectedItems()
$iCount = $oFolderView.Count
Local $aOut[$iCount +2]
$aOut[0] = $iCount
$aOut[1] = $sPath
If $iCount = 0 Then
Return ''
Else
For $oFolderItem In $oFolderView
$aOut[$n] = $oFolderItem.Name
$n += 1
Next
Return $aOut
EndIf
EndFunc ; ==>_ActiveExplorer_GetSelected
I'm able to configure a DataSource Resource in TomEE by modifying the "conf/tomee.xml" file. However, it's sort of awkward to automate this modification, as I have to insert the DataSource definition before the "" line. I heard from a comment in a related SO posting from me that it's easier to append to the "system.properties" file.
So, I tried translating this:
<Resource id="sus2" type="DataSource">
JdbcDriver = oracle.jdbc.driver.OracleDriver
MaxActive = 10
MinIdle = 2
MaxIdle = 2
MaxWait = 10000
JdbcUrl = jdbc:oracle:thin:#${DB_HOST}:${DB_PORT}:${DB_SID}
UserName = ${DB_USER}
Password = ${DB_PASSWORD}
</Resource>
Which works, to the following:
db = new://Resource?type=DataSource
db.id = Resource/sus2
db.JdbcDriver = oracle.jdbc.driver.OracleDriver
db.MaxActive = 10
db.MinIdle = 2
db.MaxIdle = 2
db.MaxWait = 10000
db.JdbcUrl = jdbc:oracle:thin:#${DB_HOST}:${DB_PORT}:${DB_SID}
db.UserName = ${DB_USER}
db.Password = ${DB_PASSWORD}
which does not work. It fails, saying it couldn't find the "Resource/sus2" resource.
The configuration reference can be found at http://tomee.apache.org/ng/admin/configuration/resources.html
You have to understand that XML attributes becomes URI query parameters then I think it will work.
In other words:
db = new://Resource?type=DataSource
becomes
sus2 = new://Resource?type=DataSource
and your db.id doesn't do anything - I think it is logged.
In short: replace all your "db" by "sus2" and it will work
I want to write a Lua script which will save and load my vars back into my program. I searched a bit in the Internet for code examples and now i have this:
--SetUp vars
accept = 1
strenght = 5
hp = 2
--create file
local f = assert(io.open("quicksave", "w"))
f:write(accept, "\n")
f:write(strenght, "\n")
f:write(hp, "\n")
f:close()
--Set vars to 0(simulate restart of program)
accept = 0
strenght = 0
hp = 0
print("accept: "..accept.." Strenght: "..strenght.." HP: "..hp)
--load in the saved vars
local f = assert(io.open("quicksave", "r"))
accept = f:read("*line")
strenght = f:read("*line")
hp = f:read("*line")
f:close()
print("accept: "..accept.." Strenght: "..strenght.." HP: "..hp)
This works fine for me, but how can I read only specific values from the file? For example: what should I do if i want to read out only the second line of the file (the var for strength)?
You can simply read and discard the first line:
--load in the second saved var
local f = assert(io.open("quicksave", "r"))
f:read("*line")
strenght = f:read("*line")
Nevertheless, I suggest you save your data as a Lua script that can be loaded with dofile. Something like:
return {
accept = 1,
strenght = 5,
hp = 2
}
Then you can load it into a local variable and read the fields you need:
local state = dofile("state.lua")
strenght = state.strenght
Note: This is Roblox's version of Lua.
I am working on figuring out how to upload a JSONEncoded table to pastebin. It says I need to acquire a login session key by sending a PostAsync with my dev key, username, and password, and waiting for a response from pastebin with my login session key. Here is my code so far:
h = game:GetService'HttpService'
pasteData = h:UrlEncode(h:JSONEncode(ImgScript))
username = 'USERNAMEHERE'
password = 'PASSWORDHERE'
h:PostAsync(
'http://pastebin.com/api/api_login.php',
'api_dev_key=DEVKEYHERE&api_user_name=' .. h:UrlEncode(username) .. '&api_user_password=' .. h:UrlEncode(password),
2
)
api_user_key = GeneratedUserKeyHere --THIS is what I am after; I don't know how to wait for a response from Pastebin to get this key!
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_dev_key=' .. api_dev_key .. 'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=1&api_paste_expire_date=N&api_paste_format=lua&api_paste_code=' .. h:UrlEncode(h:JSONEncode(ImgScript)) --ImgScript is the table,
2
)
Ok so I figured it out.
PostAsync not only sends data, but also receives the returned user key, so here is the working script.
h = game:GetService'HttpService'
api_dev_key = 'YourDevKeyHere'
api_paste_code = 'The text of your upload content here'
api_paste_private = '1' --0 public; 1 unlisted; 2 private
api_paste_name = 'The name of your paste here'
api_paste_expire_date = 'N' --N for never, 10M for 10 minutes, etc.
api_paste_format = 'lua' --The syntax highlighting
api_user_key = ''
api_paste_name = h:UrlEncode(api_paste_name)
api_paste_code = h:UrlEncode(api_paste_code)
username = 'YourUsernameHere'
password = 'YourPasswordHere'
api_user_key = h:PostAsync(
'http://pastebin.com/api/api_login.php',
'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password,
2
)
print(api_user_key) --DON'T DELETE THIS! IT IS ESSENTIAL FOR THE USER KEY TO BE GENERATED!
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=' .. api_paste_private .. '&api_paste_name=' .. api_paste_name .. '&api_paste_expire_date=' .. api_paste_expire_date .. '&api_paste_format=' .. api_paste_format .. '&api_dev_key=' .. api_dev_key .. '&api_paste_code=' .. api_paste_code,
2
)