Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Dec 30, 2021 12:51
@roganjosh by roganjosh : We understand the overall goal,
Dec 30, 2021 12:46
@AndrasDeak I agree and I learned from past feedback and this time I presented my ques clear to understand . Thanks
Dec 30, 2021 11:54
html report is in this format:

<table>
    <tr>
      <th>id</th>
      <th>Data</th>
      <th>status</th>
      <th>Connected</th>
      <th>Comment</th>
    </tr>
    [table_rows]
  </table>
Dec 30, 2021 11:52
iterate through the rows !!
Dec 30, 2021 11:46
"report_template.html" need to be stored and new "report_template.html" after generate should compare the previous report and if any differences then send_smtp_mail
Dec 30, 2021 11:41
:53741689 Difference can be any column ,like status, connected or comment which may change.
Example if both id data are same then don't send the report , if any changes
example id 2 is updated as below , so in this case we need to send the report.

2    server2   200                    False                Ok

send_smtp_mail(
        .....
        body=html_message,
        .....
        }
Dec 30, 2021 11:26
I have one function which generate and replace html report and later it use to send the report over html every day,
Can it be possible to check and compare if any difference in report then only send the html report.
Dec 30, 2021 11:26
def main():
    object_list = all_row_list()
    table_html_rows = create_table_rows(object_list)
    script_directory = os.path.dirname(os.path.realpath(__file__))
    html_report_path = os.path.join(script_directory, "report_template.html")
    html_report_as_text = get_text_file_contents(html_report_path)
    html_message = html_report_as_text.replace("[table_rows]", table_html_rows)
main()

/*sample data*/
"data Jan-1":
id   Data     status                  Connected            Comment
1    server1   200                     True                 Ok
Dec 28, 2021 09:00
@Aran-Fey Thanks for the help this what I needed It worked
Dec 28, 2021 08:26
Thanks I modified little

<td><a href="{0}">{0}</a>""".format(any_string)+"""</td>
Dec 28, 2021 08:04
how to make any_string text a hyperlink , these is been used to send mail in outlook

<td><a>{}""".format(any_string)+"""</a></td>
Dec 28, 2021 08:03
@WayneWerner Thanks
Dec 28, 2021 06:58
is there any way to combine these two append files.

sys.path.append(os.path.join(code_dir , 'files', 'tools'))
sys.path.append(os.path.join(code_dir, "files", "report"))
Dec 27, 2021 15:24
<td><a href={}""".format(send_link)+""">send_link</a></td>

this giving me error
Dec 27, 2021 15:16
Go to the path: <a href=.format"{url_link}">send_link</a>

in .format will try
Dec 27, 2021 15:15
@roganjosh Okay Thanks let me try
Dec 27, 2021 15:11
@Aran-Fey Its just I need to pass the variable value to html body content as href
Dec 27, 2021 15:08
@roganjosh I am getting the content path from env variable and that content i need to send as email as with other details.
Dec 27, 2021 15:04
@roganjosh python send mail
Dec 27, 2021 15:02
:53724025
<td>Go to the path:</td>
<td><a href="home/local/report/files">home/local/report/files</a></td>

instead I want to access using variable as send_link= "home/local/report/files"
so Go to the path: <a href="send_link">send_link</a>
Dec 27, 2021 14:58
@roganjosh oops ya typing mistake its href :-D
Dec 27, 2021 14:56
Output in mail should be like this

Go to the path: /home/local/report/files (this path in herf link format)
Dec 27, 2021 14:54
@Aran-Fey yes correct
Dec 27, 2021 14:53
@roganjosh yes we have
Dec 27, 2021 14:49
@roganjosh that send_link="/home/local/report/files" path is actually a server path.
Dec 27, 2021 14:47
@roganjosh Yes i need that path in link format. its server path
Dec 27, 2021 14:46
@MisterMiyagi in herf link format
Dec 27, 2021 14:42
Hi how to access a url link in python mail script(MIMEMultipart) example:

send_link="/home/local/report/files"

email_body = """<pre>
Go to the path: <a href="send_link">send_link</a>
Thanks,
XYZ Team.
</pre>"""

msg = MIMEText(email_body ,'html')

output wanted as

Go to the path: /home/local/report/files (this path should be in url form)
Dec 27, 2021 12:19
@roganjosh Thanks
Dec 27, 2021 12:18
@roganjosh Its based on updating the path with custom folder directory path
Dec 27, 2021 12:16
okay
Dec 27, 2021 12:09
need to remove last word from path and add new word to it (should support python 2.7)

str = 'home/ro/A_Python_Scripts/flask-auto/build'

newstr output as: 'home/ro/A_Python_Scripts/flask-auto/final'

remove build from str and add final at last

(Must be one line code)
Dec 21, 2021 13:53
@MisterMiyagi Thanks I am checking it
Dec 21, 2021 13:51
@Aran-Fey I already asked but not got any response
Dec 21, 2021 13:47
@Kevin sorry
Dec 21, 2021 13:46
In want to print user_emails in a bash file
Dec 21, 2021 13:45
:53690956
{
    "env.master_name":"admin",
    "env.user_emails":"[email protected],[email protected]"
}
Dec 21, 2021 13:38
@Kevin Its stored in Json format only I just pasted the line which i need to use in bash file
Dec 21, 2021 13:36
@Kevin ohh okay , Thanks
Dec 21, 2021 13:32
do anyone can help me with this .


how import env variables from Json to bash?

file1.json
env.email_user="[email protected],[email protected]"

file2.sh
echo $email_user
 
Dec 28, 2021 14:26
How I can reduce the code as just git delete command are based on choice number.

if [ "$choice" == "1" ]; then
	echo ""
	if [[ "$USERTYPE" == "YES" ]]; then
		git push origin --delete ${delete_branch1[*]}
	else
		echo "Cancelling..."
	fi
elif [ "$choice" == "2" ]; then
	echo ""
	if [[ "$USERTYPE" == "YES" ]]; then
		git push origin --delete ${delete_xyz[*]}
	else
		echo "Cancelling..."
	fi
elif [ "$choice" == "3" ]; then
	echo ""
	if [[ "$USERTYPE" == "YES" ]]; then
		git push origin --delete ${delete_abc[*]}
Dec 22, 2021 07:17
Okay I will check it , Thanks
Dec 22, 2021 07:14
@tripleee how to use jq in my scenario
Dec 22, 2021 07:13
I am using windows VS code and compiling as Git Bash
Dec 22, 2021 06:53
@tripleee I ran this but showing this :

./test_fetchg_env.sh: line 3: jq: command not found

I tried installing jq as brew install jq .. still jq command not found
Dec 22, 2021 06:33
Okay Thanks @tripleee
Dec 22, 2021 06:26
@tripleee

then to fetch in bash I have to do like this ??

email_user=$(jq .user_emails test_json_to_bash.json)
echo $email_user
Dec 22, 2021 06:19
:53691459 Thanks yup I just pasted wrong format

It was like this

{
    "env.master_name":"admin",
    "env.user_emails":"[email protected],[email protected]"
}
Dec 21, 2021 11:41
how import env variables from Json to bash?

file1.json
env.email_user="[email protected],[email protected]"

file2.sh
echo $email_user
 

 Python Ouroboros - The Rotating Knives

Messages from the Python room that didn't meet our standards o...
Dec 21, 2021 13:49
how import environment variables from JSON to bash?

file1.json

{
    "env.master_name":"admin",
    "env.user_emails":"[email protected],[email protected]"
}

file2.sh

echo $user_emails