IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Program Language
C#

Checks if the remote file exists

Language: C# /// <summary>Get remote file information</summary> /// <param name="url">The URL of the remote file</param> /// <returns>RemoteFile if the remote file exists, or null</returns> public static RemoteFile RemoteFileInfo(string url) { RemoteFile file = new RemoteFile(); try { var request = WebRequest.Create(url); request.Method = "HEAD"; using (var response = request.GetResponse() as HttpWebResponse) { file.LastModified = response.LastModified; file.Size = response.ContentLength; file.StatusCode = response.StatusCode; file.ContentType = response.ContentType; file.ContentEncoding = response.ContentEncoding; } } catch(Exception e) { return null; } return file; } public class RemoteFile { public DateTime LastModified { get; set; } public long Size { get; set; } public HttpStatusCode StatusCode { get; set; } public string ContentType { get; set; } public string ContentEncoding { get; set; } }  292 total views,  6 views today

2020-11-19 0 Comments 279 Views 0 Like IT Team Read more
Python

Download video from zoom

Zoom meeting recorded video and saved in mp4 format file. But it is not allowed to download. In order to overcome "access denied" error, we have to add hread informations: user agent, cookie, and referer. Here is the source code to download the video using python. import requests url="https://ssrweb.zoom.us/cmr/replay/2020/09/21/2189503564/CD309625-D877-4B35-B99F-34CA4529F0CD/GMT20200920-233653_Tom-Ren-s-_1920x900.mp4?response-content-type=video%2Fmp4&response-cache-control=max-age%3D0%2Cs-maxage%3D86400&data=b87bffbf0d63fc51fb5b53caa6a6e3be04d1fc8b436a138418c4cfce8ff64b49&s001=yes&cid=aw1&fid=eT5a1fFKL6E57JgRK8F681dHTUjCtkgCRQSIhogfoc991lO-o1SPZgBwVzAnFJVok-qWSQ3oTrbpuF_L.01AJKlG7IPx983bD&s002=ly1zSoH_nrGCD_5BpiDHTfumcztfOw0ymT3bgpFePYuEvjANCyhpAsfNHw.bIBlHettrxUuB0Ga&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dH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1QrZ8886s~ij7GU2oY7rXKzRHA__&Key-Pair-Id=APKAJFHNSLHYCGFYQGIA" content = requests.get(url, headers={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36", "Cookie": "_zm_ssid=aw1_c_rWPCvlX3Tcmc8iikrsu0Bg; _zm_mtk_guid=b2c4961722954e1890f35c83dc55fc01; zm_oauth_cluster=aw1; zm_general_guid=""5Rog1fA9Dxwqucr9rINhlQzwlU/sFl0FdC6GZtoSZp4=""; _zm_lang=en-US; zm_gnl_guid=ab1cGxWMcSkw4h2H6yO/DOPyREzINR14Ppkyl7FBOlG1eU5nI2Qnwdltx4ESb0I1odSd; zm_gnl_ruid=udw1HTAmShCudkTwo4ToCA; _zm_csp_script_nonce=JG_kdyI9T-CxO2Y4shUwHA; _zm_launcher=1597953850725; zm_gnl_guid_v2=dffcVktj7guFTpRscXSNCeINKl8xSIlozAf16PavwVWL29lhYi78Ym1sSg3l9Js/VWHPWMBeaBr7Ap6D0q0Z00gLsZb2SrCjP5C8Y=; _zm_page_auth=aw1_c_wCHnZvcWSvuMw-h46T8FIg; _zm_ctaid=51pkTNQpTz-uUZmjm4Rulw.1600739087485.c798cb33478fb73a92bac81a5f6662e2; _zm_chtaid=811; _zm_currency=CAD", "referer": "https://zoom.us/rec/play/P4ZLJUcpCuFLJBpjP7wRiBRHquR8PNIK91C3FRHSPGJ0XX39e6e88ZYmzRLhXq9djw90IHTTTKv0cxfI.QAryZuRQmCV5viBv?continueMode=true&_x_zm_rtaid=51pkTNQpTz-uUZmjm4Rulw.1600739087485.c798cb33478fb73a92bac81a5f6662e2&_x_zm_rhtaid=811" }).content # print(content) counter = 0 with open('./video/第二讲 加拿大房屋保险.mp4', 'wb') as f: # f.write(content) # f.close() for buffer in content.iter_content(chunk_size=4096): f.write(buffer) counter += len(buffer) print(counter)  188 total views,  10 views today

2020-09-21 0 Comments 167 Views 0 Like IT Team Read more
DotNET

Unicode to Chinese conversion notes

Unicode expressed like "\u4a44". Chinese words located from 0x3400 to 0x9fa5, including simplified and traditional words. Online tool: Unicode to Chinese covnerter C# Stores unicode data as a string, for each unicode in a string lookup the string by hex or integer number to get the right characters to replace them in the string. string ZHTable = "㐀㐁㐂㐃㐄㐅㐆㐇㐈㐉㐊㐋㐌㐍㐎㐏㐐... ...";   private string GetChar(string unicode) { unicode = unicode.Replace("\\u", ""); var code = Convert.ToInt32(unicode, 16); return ZHTable[code - 13312].ToString(); } var matches = Regex.Matches(text, @"\\u[a-f0-9]{4}"); string result = text; if (matches.Count > 0) { foreach (var m in matches) { var key = m.ToString(); result = result.Replace(key, GetChar(m.ToString())); } }   public string ToChinese(string text) { var matches = Regex.Matches(text, @"\\u[a-f0-9]{4}"); string result = text; if (matches.Count > 0) { foreach (var m in matches) { var key = m.ToString(); result = result.Replace(m.ToString(), GetChar(key)); } } return result; } PHP Stores unicode data in a dictionary like array, for each unicode in a string look up the dictionary to get the right characters to replace them in the string. $unicodedata = [ ... ... 0x3437 => '㐷', 0x3438 => '㐸', 0x3439 => '㐹', 0x343a => '㐺', 0x343b => '㐻', 0x343c => '㐼', ... ... ]; for number calculate as power of 16; for a-f, convert to ascii code - 87, so as a=10, f=15, then calculate as power of 16; for hex letter only has a-f, other than that throw exception. if($this->is_number($u[$i])){ $val += $u[$i] * pow(16, 3-$i); } elseif($this->is_hexletter($u[$i])){ $val += ord($u[$i])-87 * pow(16,3-$i); } to match all unicode, which…

2020-09-18 0 Comments 346 Views 0 Like IT Team Read more
Python

Data visualization with Flask

install Flask pip install flask Get Template Writing code Idea: Based on the proper visualization template, feed data from python program to the template, then render the result in the template. 1. Passing data from python to template through javascript. In Python file: from flask import Flask, render_template app = Flask(__name__) @app.route('/') def root(): divdata = '草莓,乌梅,蓝莓,红莓,白梅,话梅,绿莓'; areadata = '555,666,777'; return render_template('bigdata.html', divdata=divdata, areadata=areadata, ... ) if __name__ == '__main__': app.run(debug=True) 2. In template html file Render data as an html element, using js to convert it into js varaibles. <div id='divdata' style="display:none">{{ divdata }}</div> <div id='areadata' style="display:none">{{ areadata }}</div> <script> var divdata = document.getElementById('divdata').innerText; var datadiv = divdata.split(','); var areadata = document.getElementById('areadata').innerText; var dataarea = areadata.split(','); </script> 3. In chart js configuration file: //initialize echarts, and configure the chart var myChart = echarts.init(document.getElementById('echart1')); option = { ... xAxis: [{ type: 'category', data: datadiv, axisLine: { var data = [ { name: '海门', value: dataarea[0]}, { name: '鄂尔多斯', value: dataarea[1]}, { name: '招远', value: dataarea[2]}, { name: '舟山', value: dataarea[3]}, Result  234 total views

2020-09-13 0 Comments 213 Views 0 Like IT Team Read more
DotNET

String concatenation in c# and php

C# Using + operator Console.WriteLine("Hello" + " " + "String " + "!"); String Interpolation string author = "Mahesh Chand"; string book = "C# Programming"; string bookAuthor = $"{author} is the author of {book}."; String.Concatenate() method string fName = "Mahesh"; string lName = "Chand"; string Name = string.Concat(fName, lName); string[] authors = { "Mahesh Chand ", "Chris Love ", "Dave McCarter ", "Praveen Kumar "}; string arrayStr = string.Concat(authors); String.Join() method int[] intArray = { 1, 3, 5, 7, 9 }; String seperator = ", "; string result = "Int, "; result += String.Join(seperator, intArray); // Using String.Join(String, String[], int int) // Let's concatenate first two strings of the array String[] arr2 = { "Mahesh Chand ", "Chris Love ", "Dave McCarter ", "Praveen Kumar " }; String seperator2 = ", "; string result2 = "First Author, "; result2 += String.Join(seperator2, arr2, 1, 2); Console.WriteLine($"Result: {result2}"); String.Format() method string date = String.Format("Today's date is {0}", DateTime.Now); StringBuilder.Append() method builder.Append(", "); PHP Using . operator $b = "Hello " . "World!"; // slow String Interpolation $a = '3'; echo "qwe{$a}rty"; // double quote echo "Result: " . ($a + 3); // result 6 "{$str1}{$str2}{$str3}"; // one concat = fast   $str1. $str2. $str3;    // two concats = slow //Use double quotes to concat more than two strings instead of multiple '.' operators.  PHP is forced to re-concatenate with every '.' operator. $logMessage = "A {$user->type} with e-mailaddress {$user->email} has performed {$action} on {$subject}." Using printf() $logMessage = sprintf('A %s with email %s has performed %s on %s.', $user->type, $user->email, $action, $subject);    644 total views

2020-04-29 0 Comments 634 Views 0 Like IT Team Read more
Python

Python - Crawling images from json file

Analysis url: https://www.luscious.net/albums/cassie-laine_348936/ load images with ajax. It returns json file url: https://api.luscious.net/graphql/nobatch/?operationName=AlbumListOwnPictures&query=+query+AlbumListOwnPictures%28%24input%3A+PictureListInput%21%29+%7B+picture+%7B+list%28input%3A+%24input%29+%7B+info+%7B+...FacetCollectionInfo+%7D+items+%7B+...PictureStandardWithoutAlbum+%7D+%7D+%7D+%7D+fragment+FacetCollectionInfo+on+FacetCollectionInfo+%7B+page+has_next_page+has_previous_page+total_items+total_pages+items_per_page+url_complete+%7D+fragment+PictureStandardWithoutAlbum+on+Picture+%7B+__typename+id+title+description+created+like_status+number_of_comments+number_of_favorites+moderation_status+width+height+resolution+aspect_ratio+url_to_original+url_to_video+is_animated+position+tags+%7B+category+text+url+%7D+permissions+url+thumbnails+%7B+width+height+size+url+%7D+%7D+&variables=%7B%22input%22%3A%7B%22filters%22%3A%5B%7B%22name%22%3A%22album_id%22%2C%22value%22%3A%22348936%22%7D%5D%2C%22display%22%3A%22rating_all_time%22%2C%22page%22%3A1%7D%7D Coding json structure below. We need the highest resolution images. import requests import json from urllib.request import urlretrieve def download(url): header = { "User_Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36" } html = requests.get(url, headers=header).text #return json file jobj = json.loads(html) items = jobj['data']['picture']['list']['items'] for item in items: img = th['url_to_original'] filename = img[img.rfind("/") + 1:] filepath = 'd:/img/'+filename print(filepath) urlretrieve(img, filepath) url = "https://api.luscious.net/graphql/nobatch/?operationName=AlbumListOwnPictures&query=+query+AlbumListOwnPictures%28%24input%3A+PictureListInput%21%29+%7B+picture+%7B+list%28input%3A+%24input%29+%7B+info+%7B+...FacetCollectionInfo+%7D+items+%7B+...PictureStandardWithoutAlbum+%7D+%7D+%7D+%7D+fragment+FacetCollectionInfo+on+FacetCollectionInfo+%7B+page+has_next_page+has_previous_page+total_items+total_pages+items_per_page+url_complete+%7D+fragment+PictureStandardWithoutAlbum+on+Picture+%7B+__typename+id+title+description+created+like_status+number_of_comments+number_of_favorites+moderation_status+width+height+resolution+aspect_ratio+url_to_original+url_to_video+is_animated+position+tags+%7B+category+text+url+%7D+permissions+url+thumbnails+%7B+width+height+size+url+%7D+%7D+&variables=%7B%22input%22%3A%7B%22filters%22%3A%5B%7B%22name%22%3A%22album_id%22%2C%22value%22%3A%22348936%22%7D%5D%2C%22display%22%3A%22rating_all_time%22%2C%22page%22%3A1%7D%7D" download(url) print('done!') Result  557 total views

2020-04-22 0 Comments 548 Views 0 Like IT Team Read more
PHP

Converting asp.net website to wordpress

Situation Source Version: ASP.NET 4.0 WordPress marketshare has been dramatically increased in recently years. More and more people use WordPress for bloggin or e-commerce applications, and also moving existing site to WordPress to reduce maintenance and SEO cost in the future. Due to ASP.NET and Wordpress are totally different in technology, so converting between them directly is imposible. First try to setup a theme to accommadate the common parts, e.g. header, menu, and footer. Finally I found that it is not easy to find a suitable theme to do this task, and the page contents would be controlled by different set of stylesheet. Give up! Then try second method - the final approach. Key Points Dynamic Resources ASP.NET page contains special hidden dynamic contents: WebResource.axd and ScriptResource.axd files. These are stylesheet and javascripts files that the page rely on during rendering. Common Areas With php we can include files that contains common contents, like header, menu, footer, sidebar. include_once("./includes/header.php"); include_once("./includes/menu.php"); include_once("./includes/footer.php"); Steps Copy the folders that contains static resources to the destination. Open each page source code from browser: right click > view page source. Save the page source to local, name it with php extension. Open WebResource.axd and ScriptResource.axd links from source view, then save them to local. Rename and move to coresponding resouce folders of destination server. Change resource links on page source, remember to change the path based on step 3. Extract common contents and save to separate files with php extension. Replace and include the common contents on each page from the files in step 5.…

2019-11-20 0 Comments 485 Views 0 Like IT Team Read more
PHP

Crawling images from web with PHP

Tool Basic function https://github.com/votinhthuong/crawler_image_php Modification 1. get true image name some sites expose images with query string appended. We need to remove it. add function get_image_name($img_name) to simple_html_dom.php file. //remove image appended chars function get_image_name($img_name){ $exts = Array('jpg','png','gif','ico','webp'); $pos = ''; $imgext = ''; foreach($exts as $ext){ $pos = strpos($img_name, $ext); if(strlen($img_name) - $pos == strlen($ext)) return $img_name; if($pos>0){ $imgext = $ext; break; } } return substr($img_name, 0, $pos).$imgext; } Add one more line of code to get the image name in index.php:   $img_name = get_image_name($img_name); 2. Zip images folder General zip operations open a zip file and add files into it $zip = new ZipArchive; if ($zip->open('test_new.zip', ZipArchive::CREATE) === TRUE){    // Add files to the zip file    $zip->addFile('test.txt');    $zip->addFile('test.pdf');    // Add random.txt file to zip and rename it to newfile.txt    $zip->addFile('random.txt', 'newfile.txt');    // Add a file new.txt file to zip using the text specified    $zip->addFromString('new.txt', 'text to be added to the new.txt file');    // All files are added, so close the zip file.    $zip->close(); } Overwrite an existing zip file $zip = new ZipArchive; if ($zip->open('test_folder.zip', ZipArchive::CREATE) === TRUE) {    // Add files to the zip file inside demo_folder    $zip->addFile('text.txt', 'demo_folder/test.txt');    $zip->addFile('test.pdf', 'demo_folder/test.pdf');    // Add random.txt file to zip and rename it to newfile.txt and store in demo_folder    $zip->addFile('random.txt', 'demo_folder/newfile.txt');    // Add a file demo_folder/new.txt file to zip using the text specified    $zip->addFromString('demo_folder/new.txt', 'text to be added to the new.txt file');    // All files are added, so close the zip file.  …

2018-10-30 0 Comments 464 Views 0 Like IT Team Read more
PHP

PHP - Delete folder

In php, rmdir() is used to delete an empty folder. If the folder has files or sub folders, rmdir command would fail. This deleteDir function would use recursive approach to do the magic. function deleteDir($dirPath) { if (! is_dir($dirPath)) { throw new InvalidArgumentException("$dirPath must be a directory"); } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) { $deleteDir($file); } else { unlink($file); } } rmdir($dirPath); }  480 total views

2018-10-30 0 Comments 471 Views 0 Like IT Team Read more
Program Language

Wordpress + polylang - Globalization

Tables wp_posts: posts wp_terms: post category, menu wp_term_taxonomy: term type (taxonomy), language (description), hierarchy, number of posts associated to it wp_term_relationships: relationship between post-taxonomy,category-taxonomy when polylang activated wp_terms: add language rows: zh - post language, pll_zh-category language wp_term_relationships all posts and categories would add rows to this table in order to identify the relationships. INSERT INTO `wp_terms` (`term_id`, `name`, `slug`, `term_group`) VALUES (3, 'Socials Top Menu', 'socials-top-menu', 0), (33, '报道', 'report', 0), (38, 'English', 'enca', 2), (39, 'English', 'pll_enca', 0), (40, 'pll_5b343bccc90ae', 'pll_5b343bccc90ae', 0), (41, '中文 (中国)', 'zh', 0), --zh post language (42, '中文 (中国)', 'pll_zh', 0), --pll_zh term language (99, 'Report', 'report-calendar-enca', 0); INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES (3, 3, 'nav_menu', '', 0, 7), (33, 33, 'category', '', 13, 56), (38, 38, 'language', 'a:3:{s:6:\"locale\";s:5:\"en_CA\";s:3:\"rtl\";i:0;s:9:\"flag_code\";s:2:\"ca\";}', 0, 2), (39, 39, 'term_language', '', 0, 16), (40, 40, 'term_translations', 'a:2:{s:4:\"enca\";i:99;s:2:\"zh\";i:33;}', 0, 2), (41, 41, 'language', 'a:3:{s:6:\"locale\";s:5:\"zh_CN\";s:3:\"rtl\";i:0;s:9:\"flag_code\";s:2:\"cn\";}', 0, 9), (42, 42, 'term_language', '', 0, 17), (99, 99, 'category', '', 73, 0); INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`, `term_order`) VALUES (33, 3, 0), --nav_menu (33, 40, 0), --term_translations (33, 42, 0), --term_language (43, 33, 0), --category (54, 33, 0), --term_translations a:2:{s:4:"enca";i:53;s:2:"zh";i:20;} (99, 39, 0), --category:Report (379, 41, 0);      --post Add language row for posts after activating polylang INSERT INTO wp_term_relationships (object_id,term_taxonomy_id) SELECT id,41 FROM `wp_posts` --41: zh where id not in (select object_id from wp_term_relationships where term_taxonomy_id=41) and post_type='post'    502 total views

2018-06-29 0 Comments 496 Views 0 Like IT Team Read more
12
Chinese (Simplified) Chinese (Simplified) Chinese (Traditional) Chinese (Traditional) English English French French German German Japanese Japanese Korean Korean Russian Russian
Newest Hotspots Random
Newest Hotspots Random
Fixing Kratos theme multi-language issue How to automatically translate a website to any language Controling Category List on Sidebar Widget Restoring the Links Manager Adding reCaptcha for user forms in WordPress Scheduling Background Job in WordPress
2021 最新 DotNet 资源大全
Extend some useful string functions in C# Exam MB2-716 Dynamics 365 Customization and Configuration Set minDate and maxDate on datetimepicker from ajax dataset OneDrive for Business 文件到 Google Drive 文件 String concatenation in c# and php JQuery set selected option for supporting multi-language
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • Digital Marketing
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

THEME KRATOS MADE BY VTROIS